在模块“主要"中未定义如何避免“主要"使用合成时 [英] How to avoid "‘main’ is not defined in module ‘Main’" when using syntastic

查看:155
本文介绍了在模块“主要"中未定义如何避免“主要"使用合成时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write a module in Haskell. It does not have a main because it's not meant to be a stand-alone program.

我刚开始使用合成词,并且不断报告:

I just started using syntastic, and it is constantly reporting:

The IO action ‘main’ is not defined in module ‘Main’

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

This is preventing it from reporting other real errors in my module. If I try to work around this by adding a dummy main, it starts complaining that everything else is "Defined but not used".

我该如何告诉syntastic(以及幕后使用的任何检查器),应该没有main?

How can I tell syntastic (and whatever checker it's using under the covers) that there isn't supposed to be a main?

推荐答案

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

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.

出现此警告的原因是,默认情况下,在Haskell中,任何未声明的模块都具有名称Main.由于您尚未定义main :: IO ()且模块名称隐式为Main,因此ghc-mod会发出警告.如果您声明它不是Main之外的东西,ghc-mod会认为您只是在导出模块中的所有内容,因为所有内容都是从模块中隐式导出的.

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.

这篇关于在模块“主要"中未定义如何避免“主要"使用合成时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆