You have to use case
expressions. For example:
raizes2 :: Float -> Float -> Float -> (Float, Float)
raizes2 a b c = let delta = (b^2 - 4*a*c)
in case compare delta 0 of
LT -> error "Delta nao pode ser menor que zero"
_ -> if a == 0
then error "A nao pode ser zero"
else ( (-b + (sqrt(delta)))/2*a
, (-b - (sqrt(delta)))/2*a )
It's a little different because case
only compares equalities. And what is compared is static, that is, it will always be the result of compare delta 0
, which can be LT
, GT
or EQ
. Since its patterns involve the comparison not only of the delta
value, it is necessary to use the _
(which accepts anything) case and within it to create a if
(or other case
) to compare the value of a
.
If you want to read a little about these structures, the page about case
is translated into Wikibook in Portuguese .