|
Re: Begginer question: msg#00053lang.haskell.cafe
Maurício <briqueabraque@xxxxxxxxx> writes: > complex_root :: (Float, Float, Float) -> (Complex Float, Complex Float) > complex_root (a,b,c) = (x1,x2) where { > delta = b * b - 4 * a * c :: Float; > sqr_delta = if delta >= 0 then (sqrt delta) :+ 0 else 0 :+ > (sqrt delta) :: (Complex Float); > > x1 = (b + sqr_delta)/(2 * a); > x2 = (b - sqr_delta)/(2 * a); > } > Couldn't match `Float' against `Complex Float' > Expected type: Float > Inferred type: Complex Float > In the second argument of `(+)', namely `sqr_delta' > In the definition of `x1': x1 = (b + sqr_delta) The error message says it all, really. If you examine the definition of x1, you see that (+) is applied to two variables. If you check these, you will discover that they have different types, which is the cause of the error. Note that Haskell doesn't automatically convert arguments for you -- this is a feature. -kzm -- If I haven't seen further, it is by standing in the footprints of giants |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Begginer question: 00053, Jules Bean |
|---|---|
| Next by Date: | RE: Re: Utility functions: 00053, Simon Marlow |
| Previous by Thread: | Re: Begginer questioni: 00053, Jules Bean |
| Next by Thread: | Re: Begginer question: 00053, Maurício |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |