作为一名计算机科学专业的大三学生,我自己尝试在秋假期间临时抱佛脚学习 Haskell(对于我自己来说……不知道为什么我要折磨自己)。我下载了 IntelliJ 并安装了 Jetbrains 的官方 Haskell 插件。
我正在遵循“为伟大的利益而学习 Haskell!”的指示
编译此代码时:
test = putStrLn "Hello World!"
我收到此错误:
Information:Compilation completed with 2 errors and 1 warning in 2 sec
Information:2 errors
Information:1 warning
Error:cabal: build errors.
Warning:ghc: warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
^
/Users/<USER_NAME>/Documents/Dropbox/Developer/IntelliJ/src/Main.hs
Error:(1, 1) ghc: The function `main' is not defined in module `Main'
我在使用文本编辑器和终端时没有这个问题...但是我喜欢 IDE(对不起 VIM 伙计们)。另外,我正在运行 OS X 10.9,根据我的研究,已知它会导致问题。
最佳答案
您缺少 main
函数,就像错误告诉您的那样。只要有:
main :: IO ()
main = putStrLn "Hello World!"
或者:
test :: IO ()
test = putStrLn "Hello World!"
main :: IO ()
main = test
如果仍然给您带来问题,请在文件的开头添加:
module Main where
关于 haskell N00b : IntelliJ giving two errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26309446/