How to avoid "‘main’ is not defined in module ‘Main’" when using syntastic
Asked Answered
G

2

28

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".

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

Gayn answered 28/5, 2015 at 23:50 Comment(1)
Just add module Foo where at the beginning.Overcoat
S
31

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.

Scrapple answered 29/5, 2015 at 0:23 Comment(0)
E
9

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

main :: IO ()
main = return ()
Electroballistics answered 14/8, 2019 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.