[MLton] Structures inside a function?

Wesley W. Terpstra terpstra@gkec.tu-darmstadt.de
Fri, 21 Jan 2005 22:26:23 +0100

On Fri, Jan 21, 2005 at 07:34:10AM -0800, Stephen Weeks wrote:
> A trick I sometimes use when I'm this situation and don't want to
> refactor in the other way's y'all have discussed is to use a ref cell
> to delay instantiation of part of the structure.  In your case, the
> lone value to be delayed is modulus, but in general, any number of
> values could be delayed.  Once enough values are delayed, one can lift
> the functor applications to the top level, leaving just the value part
> inside the function.

Thank you!

The only issue I see with it is that several things depend on the value of
the modulus. For example, the order of the resulting ring (number of
elements) is calculated from it. Furthermore, functors like
	functor DiscreteLogarithm(G : CYCLIC_GROUP) = ..
need to factor (in the integer sense) the order of groups.

This calculation right now is performed at structure instantiation.
Then the logarithm method re-uses the factorization in its computations.

It's really unfortunate that MLton doesn't unroll recursion. As long as you
don't exceed the inlining size limit, I think it would be a real performance
gain. For things like my work, it would mean that factorization could be
performed at compile time and just the list of factors would be hard-coded.
Not to mention, loop unrolling really helps for C...

Even my C++ implementation does the factorization at compile time.
You're not telling me that C++ is more expressive now are you? ;-)

Wesley W. Terpstra