nRaizes :: Floating a => a -> a -> a -> a
nRaizes a b c = let r = b^2 - 4 * a * c
in if r < 0
then 0
else if r == 0
then 1
else 2
So I got this code, where I'm checking for the number of roots of an equation. But when I try to compile it, it gives me this.
Could not deduce (Ord a) arising from a use of ‘<’
from the context (Floating a)
bound by the type signature for
nRaizes :: Floating a => a -> a -> a -> a
at Ficha1.hs:29:14-43
Possible fix:
add (Ord a) to the context of
the type signature for nRaizes :: Floating a => a -> a -> a -> a
In the expression: r < 0
In the expression: if r < 0 then 0 else if r == 0 then 1 else 2
In the expression:
let r = b ^ 2 - 4 * a * c
in if r < 0 then 0 else if r == 0 then 1 else 2
Ficha1.hs:33:32:
Could not deduce (Eq a) arising from a use of ‘==’
from the context (Floating a)
bound by the type signature for
nRaizes :: Floating a => a -> a -> a -> a
at Ficha1.hs:29:14-43
Possible fix:
add (Eq a) to the context of
the type signature for nRaizes :: Floating a => a -> a -> a -> a
In the expression: r == 0
In the expression: if r == 0 then 1 else 2
In the expression: if r < 0 then 0 else if r == 0 then 1 else 2
Yes, I'm a begginer. I seriously cannot even understand what is wrong. It's a floating number, why can't it compare it? I just know it has something to do with the signature, because if I remove it it works