monomorphizing ML programs

Bernard James POPE bjpop@cs.mu.OZ.AU
Thu, 9 Nov 2000 13:14:16 +1100 (EST)


Hi Stephen (and other MLton folk),

Thankyou very much for your prompt reply and helpful information. 
I am very pleased to read about your technique - it is essentially the
same thing that I do for Haskell programs. Up until now I thought that I was
the only person doing this. It is somewhat reassuring that other people take
the same approach. Note that I am not performing the transformation for
compilation purposes, but rather for debugging purposes.

> It is very straightforward.  MLton translates source SML into an explicitly
> typed polymorphic intermediate language.  A single pass over a program in this
> IL determines the types at which each polymorphic function is applied, and
> creates a duplicate version of a function for every combination of types at
> which it is applied.  Datatype declarations are duplicated similarly.  There is
> some messiness because of "non-uniform" datatypes (I don't know if Haskell has
> those).

Haskell has non-uniform data-types and it also has polymorphic recursion.
I see that SML does not have polymorphic recursion. When we encounter
polymorphic recursion, we basically throw our hands in the air and say that
we can't transform that declaration (which means that we cannot also debug
calls to it). This is fairly serious, but it still means we can debug the
rest of the program. It would probably be worse for a compiler that relied
on monomorphising all functions.

I imagine that you are still using the whole-program compilation scheme, which
means you don't have any problems about module boundaries? Calls across 
module boundaries cause problems for us, and with mutually recursive modules
we have to fix-point (groan).

> Here are a few other pointers to info about MLton's monomorphisation.
> 
> There are a a few (old) syntax tree size increase (due to monomorphisation)
> measurements on page 11 of 
> 	http://www.star-lab.com/sweeks/papers/99-intertrust.ps
> 
> There is also some description on pages 13-19 of
> 	http://www.star-lab.com/sweeks/papers/98-princeton.ps
> 
> Also, I've attached a section from an unpublished document that describes
> MLton's monomorphisation.  And of course, there is the code, which is less than
> 500 lines of the MLton sources.  If you grab the MLton SRPMs, you can find the
> monomorphisation code in the file src/mlton/xml/monomorphise.fun.
> 
> I hope this helps, and let us know if you have further questions.

This is extremely helpful. I have read your papers and will look at the code
soon. I appreciate your help.

Regards,
Bernie.