Haskell error parse error on input `=’

haskell

I'm new to Haskell and after starting ghci I tried:

f x = 2 * x

and I obtained:

<interactive>:1:4: parse error on input `='

which I don't understand.

Strangely, it worked well before. I suppose that I have done misconfigured Haskell. Reinstalling ghc6 doesn't solve the problem.

For information, I use Ubuntu 10.4 and the version of ghc6 is 6.12.1-12

Best Answer

In GHCi 7.x or below, you need a let to define things in it.

Prelude> let f x = x * 2
Prelude> f 4
8

Starting from GHC 8.0.1, top-level bindings are supported in GHCi, so OP's code will work without change.

GHCi, version 8.0.1.20161213: http://www.haskell.org/ghc/  :? for help
Prelude> f x = x * 2
Prelude> f 4
8
Related Topic