Dynamically choosing the main function

Brandon Allbery allbery.b at gmail.com
Sun Nov 12 18:03:52 UTC 2017


On Sun, Nov 12, 2017 at 11:18 AM, Harendra Kumar <harendra.kumar at gmail.com>
wrote:

> GHC allows choosing a main function at link time using the "-main-is"
> option. I was wondering if there is a possibility to choose the main
> function at runtime. Or even better, if something equivalent to "ghc -e"
> is somehow possible in a linked binary executable. If not, are there any
> plans to achieve something like that in future? Are there any theoretical,
> practical obstacles to that?
>

-e is just running the compiler's bytecode backend on an expression from
the command line instead of a declaration from a file. It's not related to
this.

I might point out that this is not at all common from any language. A
limited (and Unix-specific) mechanism is to have main pick from a list of
fixed operating modes based on the program's basename, which can be set in
the filesystem by making a hard link to the executable with a different
basename.

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20171112/e0e76479/attachment.html>


More information about the ghc-devs mailing list