4
votes

I have a haskell file test.hs. In this file I have written a function

doubleMe x: x + x

this is the only function in this file test.hs. In the ghci command prompt I have typed ":l test.hs" without quotes. The following error comes up:

compiling main  <test.hs interpreted>
test.hs:1:1 Parse error: naked expression at top level
Failed: modules loaded:none

What will be the cause of this error.

I have gone through Haskell Error - Naked Expression at Top Level

and

what is parse error: naked expression at top level?

It did not help.

1
That looks like you're trying to write Python, not Haskell. Their syntaxes are not the same.Axman6

1 Answers

12
votes

You need = rather than :, so:

doubleMe x = x + x

If you try to use :, GHC parses this as using the : operator on doubleMe x and x + x. This is a function application, so it is an expression (an expression is basically a series of tokens that has a result). Since it isn't wrapped in a function or variable declaration it is a "naked expression", and this is an error.