unfold

Stephen Weeks MLton@sourcelight.com
Tue, 17 Jul 2001 18:14:20 -0700


> Yes, although I would do 2 slight changes:
> 1. I would use `if i = n' as the termination condition.  It is the real
>    termination condition, with >= just being used for the ease of optimization.
>    (Not a strong objection by any means.)

True.  Maybe with some of the ideas used in bounds check elimination I will be
able to get the = test as well.  Although I don't completely agree with your
earlier claims about using Overlow detection to detect buggy loops.  I would
prefer to put a single test before the loop rather than use a jo per iteration.
It's clearer and faster.  Hopefully, with the single test before, the overflow
detection will be able get the = test as a terminator.  Otherwise, it's
impossible, since the "precise exception" semantics of SML requires the loop to
be iterated until the Overflow, performing any side effects that need to happen.

> 2. I would call the results of the call to f (b, a') instead of (b, a).

Yep.

> I'm assuming that then List.tabulate will be written as an application of
> unfold.

Yep.

> Ah yes, these are much better functions for generating things.  Did you see
> any uses in the compiler?

There are lots of uses in my library, and hence in the compiler.

> Currently, does Vector.tabulate cheat and cast the result into a Vector from
> an array?  I guess it must.

Yes, that happens in the basis library.  Vector.unfold will have to do the cheat
now, but now hopefully no one else will have to.