Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Parse Error - Naked Expression at Top Level

Tags:

haskell

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.

like image 635
Vinod Avatar asked Dec 15 '22 22:12

Vinod


1 Answers

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.

like image 186
huon Avatar answered Jan 04 '23 22:01

huon