[MLton-devel] flattening

Stephen Weeks MLton@mlton.org
Sat, 28 Sep 2002 18:03:27 -0700

Myur, one experiment with flattening that I always thought would be
interesting to try, but haven't had the time, would be to write a
flattener for our SSA IL that flattens all tuple types so that *none*
remain.  That is, whenever there is a function that takes a tuple
argument, it is changed to an n-ary function, with one argument for
each component of the tuple (recursively).  For example

fun f (x: (a * b) * c) = ...

would become

fun f (x: a, y: b, z: c) = ...

Similarly, every constructor that takes a tuple argument is fully

After doing this, no tuple types will remain anywhere in the program
(it is an interesting property of SML that this can be done).

In principle, this approach could cause problems, with

val x1 = (x0, x0)
val x2 = (x1, x1)
val x3 = (x2, x2)
val x4 = (x3, x3)

But in practice, it's probably not so bad.

Anyways, this is the most extreme approach to flattening, and any
other approach, including the one we currently use, falls somewhere
between "flatten nothing" and this approach.

I think it would be a good introduction to the SSA IL and a reasonably
simple project to implement, if you're interested.

This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
MLton-devel mailing list