Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make GHC accept Main module with a main function that isn't IO ()

Tags:

haskell

ghc

Is there some way (flag or hack) to make GHC accept a main module where the main function's signature isn't IO ()? For Fay the main functions have the type Fay (), but GHC does not accept this if the module is Main (or the module name is left out).

like image 559
Adam Bergmark Avatar asked Dec 27 '22 16:12

Adam Bergmark


1 Answers

The entry point to the programme must have type IO a for some a, and as far as I know, there is no way to make GHC accept other types (without modifying its source code).

By default the entry point is Main.main, but you can specify different actions as entry points using the -main-is flag with GHC. The general form is

ghc -main-is Module.action ModuleThatImportsEverything.hs -o programme

You can omit the Module part if the module is Main,

ghc -main-is action ModuleThatImportsEverything.hs -o programme

or the actionpart, if its name is main,

ghc -main-is Module ModuleThatImportsEverything.hs -o programme

is equivalent to -main-is Module.main.

For your case, you can add a dummy action to the Main module, or a dummy module - that of course needs to be imported (directly or indirectly) from the Main module - to the programme to stand in as the entry point as far as GHC is concerned.

like image 152
Daniel Fischer Avatar answered Mar 23 '23 04:03

Daniel Fischer