Mark Needham

Thoughts on Software Development

Archive for the ‘Haskell’ Category

Haskell: parse error on input `='

with one comment

I've been trying to follow the 'Monads for Java/C++ programmers' post in ghci and getting the following type of error when trying out the code snippets:

Prelude> a = 3
 
<interactive>:1:2: parse error on input `='

I figured there must be something wrong with my installation of the compiler since I was copying and pasting the example across and having this problem. Having reinstalled that, however, I still had the same problem.

I eventually came across this blog post which points to a mailing list thread from a few years ago where pjd explains that the 'let' construct is required when defining a variable from ghci and wouldn't necessarily be needed in a normal program:

pjd osfameron: about the ghci thing, you have to prefix definitions with "let"

as in: let simple x y z = x * (y + z)

pjd the reason for this is that ghci is in an implicit do block

pjd so it's not exactly like top-level haskell

We have to use a 'let' in front of any variable/function definitions and then it will work as expected:

Prelude> let a = 3
3

According to Real World Haskell:

This syntax is ghci-specific
The syntax for let that ghci accepts is not the same as we would use at the “top level” of a normal Haskell program.

Written by Mark Needham

April 22nd, 2010 at 11:35 pm

Posted in Haskell

Tagged with