How to avoid “‘main’ is not defined in module ‘Main’” when using syntastic

懵懂的女人 提交于 2019-12-03 01:18:15

Testing with ghc-mod (which backs syntastic, although hdevtools is possible too):

$ cat test1.hs
f :: Int -> Int
f x = x + 1
$ ghc-mod check test.hs
test1.hs:1:1:The IO action 'main' is not defined in module 'Main'
$ cat test2.hs
module Test where

f :: Int -> Int
f x = x + 1
$ ghc-mod check test.hs
$

So you can just put a dummy module declaration in your file and the warning will go away.

The reason why this warning pops up is because by default in Haskell any undeclared module has the name Main. Since you haven't defined a main :: IO () and the module name is implicitly Main ghc-mod throws a warning. If you declare it to be something other than Main, ghc-mod thinks you're just exporting everything in the module, since everything is implicitly exported from a module.

Though it is a late to answer, for the sake of completion adding the following will stop the warning.

main :: IO ()
main = return ()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!