Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell -- how to create a binary from a non-Main module?

I often have situations where I leave main :: IO () functions in tests. I can run these fine with runghc, but sometimes I want to compile them (e.g. for running on another platform). Is there a way to do this? If I run, for example,

ghc --make Test.Haar

where Test/Haar.hs has a main method, then nothing happens, it just creates the .o file.

like image 556
gatoatigrado Avatar asked Nov 05 '11 11:11

gatoatigrado


2 Answers

ghc --make -main-is Test.Haar Test.Haar
like image 164
nponeccop Avatar answered Nov 16 '22 12:11

nponeccop


Note, however, that after using -main-is Test.Haar, if you want to use the module as part of another programme, you have to recompile it without the -main-is, otherwise the linker will find two entry-points and throw an error.

like image 22
Daniel Fischer Avatar answered Nov 16 '22 13:11

Daniel Fischer