Reputation: 89
I am totally new to Haskell and try to follow the script in lecture notes. I created a file called lecture.hs
root (a, b, c) = ((-b -r)/e, (-b + r)/e))
where d = b*b - 4*a*c
r = sqrt d
e = 2*a
when I load this file to hugs it shows
ERROR "lecture.hs":3 - Syntax error in input (unexpected `=')
and when I load it to ghci it shows
[1 of 1] Compiling Main ( lecture.hs, interpreted )
lecture.hs:3:14: parse error on input `='
Failed, modules loaded: none.
Please help me out. Thanks!
Upvotes: 2
Views: 308
Reputation: 34398
As pasted here, your snippet is syntactically valid. In any case, the following is sure to work:
root (a, b, c) = ((-b -r)/e, (-b + r)/e)
where
d = b*b - 4*a*c
r = sqrt d
e = 2*a
Naturally, indentation style is to a significant extent a personal choice. I like placing where
in a separate line because that way I can indent the code predictably in four space steps. Whatever style you choose, don't use tabs to indent, as that leads to a lot of confusion.
Upvotes: 4