[MLton] Main.main idiom

Matthew Fluet fluet@cs.cornell.edu
Wed, 8 Sep 2004 08:27:17 -0400 (EDT)


> Maybe there is a slightly bigger problem to solve that can be solved
> without a new option.

Well, we're always talking about making the barrier to entry low.  I spent
20mins with the TA for the undergrad compilers course (using Appel in SML)
walking him through .cm files & ml-build and seeing some distaste at not
getting an actual executable at the end of the day.  I pointed out that
using mlton, you would get an executable, but since we had rigged things
for ml-build, he would need yet another source file to actually call the
main function.

You are right that part of the issue is coming from SMLofNJ.  If we took
his original source file:

structure XYZ =
struct
 ...
end

fun main () = print "Hello\n)

val _ = main ()


then it would have worked just fine in MLton without any additional work.

I personally encounter it not only in the mlton sources, but in building
the ml-doc tools under MLton.  It ends up being a two-stage process --
using cm2mlb to produce a sources.mlb and then tacking on a call-main.sml
to the end.  I've pushed all this work into the Makefile, but it is still
a side step.