haskell/play-haskell

Compile non-Main modules

dyniec opened this issue · 3 comments

Feature request

Right now to inspect core/asm output you need to write empty main function. If you want to inspect specific function, you need to either export it, or call it in main, and hope simplifier doesn't inline it completely(unless that's what you are hoping for).

It would be nice to allow compilation of modules that are not Main, since that would remove the need to write empty main function.
This together with snippet module M where would make it easy to see core/asm dump of all top-level definitions.

Workaround for now is to specify module Main module on top, export selected (or all) functions, and write empty main (see here Working version vs no main or no exports).

As for implementation, removal of -o Main flag from stage-3.sh could be enough to make it work (I don't have ghc on hand right now to check if that would really work).

Thanks for the request! This has been on my mind too.

  • How should we detect this? As far as I know there is no easy way to query the name of the module that a Haskell file represents; I'd like to avoid having to go to the GHC API here. Textual search for "module" or similar are way too fragile, and haskell-src-exts is also kind of awkward since I'd like users to be able to use all the extensions.
  • Assuming we know on the worker (which compiles&runs programs) that a module is not a Main module, what do we do if the user wanted to Run? Do we just assume that a module is Main when the user wants to Run, and give back the error that GHC will print (The IO action ‘main’ is not defined in module ‘Main’)?

Oh, now I see what you mean! GHC already does the right thing if you just don't tell it to -o Main. :)

You were entirely correct. With that tiny change, what you want just works, with the only snag that you do need to write module Something where if your file doesn't have a main.

GHC already does the right thing if you just don't tell it to -o Main. :)

Good to hear that!
Thanks for fast response and implementation :)