如何避免在使用合成时在模块'Main'中定义''main'

Lau*_*ves 25 haskell syntastic

我正在尝试在Haskell中编写一个模块.它没有,main因为它不是一个独立的程序.

我刚开始使用syntastic,它不断报告:

The IO action ‘main’ is not defined in module ‘Main’
Run Code Online (Sandbox Code Playgroud)

这可以防止它报告我的模块中的其他实际错误.如果我尝试通过添加虚拟主体来解决这个问题,它会开始抱怨所有其他内容都是"已定义但未使用".

我怎么能告诉我们不应该是一个合成器(以及它在幕后使用的任何检查器)main

bhe*_*ilr 29

测试ghc-mod(支持合成,虽然也可以使用hdevtools):

$ 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
$
Run Code Online (Sandbox Code Playgroud)

因此,您只需在文件中放置一个虚拟模块声明,警告就会消失.

弹出此警告的原因是因为默认情况下Haskell中任何未声明的模块都具有该名称Main.由于你没有定义a main :: IO ()和模块名称是隐式Mainghc-mod抛出警告.如果你声明它不是Main,ghc-mod认为你只是导出模块中的所有内容,因为所有内容都是从模块中隐式导出的.


Rus*_*llB 6

虽然这是一个迟到的答案,但为了完成添加以下内容将停止警告。

main :: IO ()
main = return ()
Run Code Online (Sandbox Code Playgroud)