Why does the Haskell interpreter (GHCI 7.10.3) need function definitions to be in a let expression, but the Haskell compiler (GHC 7.10.3) throws a parser error if a function definition is within a let expression?
I'm working through "Learn You a Haskell for Great Good!" Baby's first function is doubleMe: doubleMe x = x + x
Why does the interpreter accept this definition if it is within a let expression and otherwise throw a parse error on input '='? Meanwhile, if I'm compiling the same function from a file, why does GHC throw a parse error if the function definition is within a let expression and compiles the definition if it is not within a let expression? Coming from a Lisp background, I'm surprised that interactive Haskell and file loading and compilation Haskell treats these definitions differently.
1+1
would be an error, as well asprint (2,3)
. Instead, GCHi chose to use a little magic so to accept both these expressions andlet
definitions. About whyx=1
without let is rejected -- I don't think there's a clear answer to that except "it would require more magic". – chidoubleMe x = x + x
. Enough people like you complained that they added a special case for this. :) – Alec