什么是分析错误:顶级裸体表达? [英] what is parse error: naked expression at top level?
问题描述
我试图得到每个元素的长度,给定一个嵌套列表;我也想摆脱重复的长度。
例如,一个嵌套列表 [[1],[1,2],[4..5]]
应该给我 [1,2]
。
我可以在交互中通过nub (地图长度[[1],[1,2],[4..5]])
。但是,如果我使用以下代码编写文件:
导入Data.List
getLen :: [[a] ] - > [Int]
getLen xs = nub(地图长度xs)
I有错误说:
解析错误:顶级裸体表达式
这个错误是什么意思,我该如何解决这个问题?
,导入Data.List
看起来像数据构造函数的导入的应用程序, Data.List
作为它的参数。
由于在解析过程中发生此错误,因此编译器尚未发现数据构造函数 Import
或 Data.List
确实存在,但它确实知道像这样的表达式不允许在顶层。
当然,在这种情况下,@augustss指出这只是一个错字。
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?
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.
这篇关于什么是分析错误:顶级裸体表达?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!