开发者

what is parse error: naked expression at top level?

开发者 https://www.devze.com 2023-03-10 06:41 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消