PDA

View Full Version : "Where" clause - Haskell


nuky
03-19-2004, 06:30 AM
Hi,

I know this query is probably a very basic one but I am a beginner and am trying my best with online tutorials.

I am trying to compile the following code which finds the roots of a quadratic equation (ax^2 + bx + c):

roots :: (Float, Float, Float) -> (Float, Float)
roots (a, b, c)
|(a == 0) = error "n"
|(d < 0) = error "c"
| otherwise ((-b-r)/e, (-b+r)/e)
where { d= b * b - 4 * a * c;
r = sqrt d;
e = 2 * a }

But I am getting the following error at line 6:
Syntax error in declaration (unexpected keyword "where").

Please can anyone tll me what's wrong with this code. I have looked up several online tutorials and from what I can figure I have used the "where" clause correctly.

Any help would be GREATLY appreciated! :)

nuky
03-19-2004, 01:36 PM
In reply to my own thread...

I have figured out the problem. It was with the "otherwise" statement and not the "where" clause. I simply forgot to put the "=" after the "otherwise".

Thanks to everyone that read the post...

jemfinch
03-23-2004, 07:22 PM
Also note that Haskell uses indentation significantly, so remember to use code tags next time you post some code.

Jeremy