haskell / play-haskell

Haskell Playground
125 stars 8 forks source link

Compile non-Main modules #13

Closed dyniec closed 1 year ago

dyniec commented 1 year ago

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

tomsmeding commented 1 year ago

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

tomsmeding commented 1 year ago

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.

dyniec commented 1 year ago

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 :)