what is parse error: naked expression at top level?
I was trying to get the length of each element, given a nested list; and I also I want to get rid of the repeated length.
For example, a nested list [[1],[1,2],[4..5]]
should give me [1,2]
.
I can do it in the interactive by nub (map length [[1],[1,2],[4..5]])
. But 开发者_开发问答if I write a file with the following code:
Import Data.List
getLen :: [[a]] ->[Int]
getLen xs = nub (map length xs)
I got the error saying:
"Parse error: naked expression at top level"
What does this error mean and how can I fix this?
Simple change: it's import
not Import
.
In the parser, Import Data.List
looks like an application of the data constructor Import
with the data constructor Data.List
as its argument.
Since this error occurred during parsing, the compiler has not yet figured out that neither of the data constructors Import
or Data.List
actually exist, but it does know that an expression like this is not allowed at the top level.
Of course, in this case it was just a typo as @augustss pointed out.
精彩评论