[Haskell-cafe] Begginer question
Ketil Malde
ketil at ii.uib.no
Thu Jan 6 05:26:12 EST 2005
Maurício <briqueabraque at yahoo.com> 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
More information about the Haskell-Cafe
mailing list