r/haskellquestions • u/spartan12321 • Oct 10 '18
Multiple variables defined inside function
I get error on this code if i want ot declare second variable
foo x =
y + yy
where y = x + 1
yy = (-x)
My example is much more complicated, this is simplifed version. I can't find example of declaring multiple variable inside function. Is this incorect way of thinking and I should add two functions as parameters instead?
0
Upvotes
6
u/wewbull Oct 10 '18
Put 4 spaces at the start of each line to preserve the formatting in reddit. Then people can see how you've laid out the code.
4
u/ihamsa Oct 10 '18
I get error
This is useless.
I'm getting this error:
funny.hs:3:1: error:
parse error (possibly incorrect indentation or mismatched brackets)
|
3 | y + yy
| ^This is something that can be discussed.
12
u/Tayacan Oct 10 '18
So it's hard to see because of the way you formatted your code, but it's probably an indentation error. Within a where-block, everything should line up, like this:
Or perhaps like this: