On Sun, Nov 12, 2017 at 11:18 AM, Harendra Kumar <harendra.kumar@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@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net