Showing bondage where the main module

I have a project with this structure:

foo.cabal src/ Foo/ Main.hs 

and the foo.cabal part looks like this:

 executable foo main-is: Foo/Main.hs hs-source-dirs: src 

Main.hs has the package name Foo.Main . When I create it, it compiles everything, but does not create an executable file, since it says that there is no main module.

 Warning: output was redirected with -o, but no output will be generated because there is no Main module. 

What am I doing wrong?

[EDIT] If I move Main up one level and change foo.cabal to read main-is: Main.hs , it works. Can I have a nested module name for Main?

+5
source share
1 answer

The Main module should be called Main , not Foo.Main or anything else. If you want Foo.Main , then rename Main something like defaultMain , then create the top-level module Main , which imports Foo.Main (defaultMain) and defines main = defaultMain , for example:

 src/ Foo/ Main.hs Main.hs foo.cabal 

Where

 -- src/Foo/Main.hs module Foo.Main ( defaultMain ) where defaultMain :: IO () defaultMain = putStrLn "Hello, world!" 

and

 -- src/Main.hs module Main where import Foo.Main (defaultMain) main :: IO () main = defaultMain 

Alternatively, you can save it to Foo.Main.main and simply import it qualified.

+9
source

Source: https://habr.com/ru/post/1209660/


All Articles