I'm confused by Haskell's parsing rules.
This works beautifuly:
n = 5
m = 6
b = case (n, m) of
(5, 6) -> True
_ -> False
main = print b
Let's complicate it only a teeny tiny bit, let's add a let
to the mixture:
b =
let res = case (n, m) of
(5, 6) -> True
_ -> False
in not res
(Note, for brevity I'm omitting definitions of n
, m
and main
from now on; they carry on the same, I'm only changing b
)
Oops, problems here:
wtf.hs:5:5: error: parse error on input ‘(’
Failed, modules loaded: none.
I don't know, maybe that's some kind of a weird indentation rule that I'm not getting. Fine, let's put explicit brackets:
b =
let res = case (n, m) of {
(5, 6) -> True
_ -> False }
in not res
Still not?!
wtf.hs:6:7: error: parse error on input ‘->’
Failed, modules loaded: none.
I'm totally confused. I don't know what to do. Why won't this work?? Let's add an explicit semicolon here, even though this is honestly a blind shot and even though I don't understand why would it be needed here, because after all, AFAIK, a newline (which is present here) should make semicolons redundant:
b =
let res = case (n, m) of {
(5, 6) -> True;
_ -> False }
in not res
And this finally works!
... don't know, maybe the problem lies in let
and case
being on the same line. As a last attempt to research this myself, let's try this:
b =
let res =
case (n, m) of
(5, 6) -> True
_ -> False
in not res
This however won't work for reasons that are mysterious to me:
wtf.hs:5:5: error:
parse error (possibly incorrect indentation or mismatched brackets)
Failed, modules loaded: none.
Seriously, I'm confused here. Why are explicit brackets and semicolons needed here? (And are they? Can the code be formatted in such a way that they are not needed?)
Which obscure parsing rule of Haskell I'm not getting here?