2
votes

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?

2

2 Answers

9
votes

Simple change: it's import not Import.

2
votes

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.