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.
You need
=rather than:, so:If you try to use
:, GHC parses this as using the:operator ondoubleMe xandx + 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.