Haskell 错误:输入上的分析错误‘;其中’;|4 |式中fyx=[x]:y |^^^^^

Haskell 错误:输入上的分析错误‘;其中’;|4 |式中fyx=[x]:y |^^^^^,haskell,Haskell,main=return()--这告诉main什么也不做 main :: IO () -- This says that main is an IO action. drop 95 (foldl f [] [1..100]) where f y x = [x]:y 正确,这是名为main的过程的类型签名 main :: IO () -- This says that main is an IO action. 这句话是胡说八道。表达式在顶级无效。假设我告诉一个C编译器1+7。这

main=return()--这告诉main什么也不做

main :: IO ()    -- This says that main is an IO action.
drop 95 (foldl f [] [1..100])


where f y x = [x]:y
正确,这是名为
main
的过程的类型签名

main :: IO ()    -- This says that main is an IO action.
这句话是胡说八道。表达式在顶级无效。假设我告诉一个C编译器
1+7
。这是什么意思?这似乎不合理

也许,在给main一个类型之后,您打算定义main:
main=…
。即使如此,
drop
功能也不是IO操作。您可能希望执行计算,然后以某种方式使用结果,比如将其打印到屏幕上

drop 95 (foldl f [] [1..100])
同样,如果没有过程的定义,这也是毫无意义的,比如我在
main=…
中提出的。想象一下,我说的是“看电影”,而没有说“七点见”——上下文相当关键

综上所述,我怀疑您正在寻找:

where f y x = [x]:y

请注意,
的缩进,其中
很重要。

语法是学习语言的第一个障碍。为了了解它,我会从比你现在尝试的简单得多的例子开始,然后再努力学习更难的东西
main :: IO () -- a type signature much like a C prototype
main = print (drop 95 (foldl f [] [1..100]))
  where f y x = [x]:y