unfold and flattening
Henry Cejtin
henry@sourcelight.com
Wed, 18 Jul 2001 16:10:36 -0500
In the old code, what is the +? infix function? Also what is the array
function, which only takes a size argument and not an element to fill the
resulting array with? Also I'm surprised that you use the basis curried
List.foldl.
Also you optimize the case where the list has a single element in the old
code and you optimize the case where the list has no elements in the new
code. Why the change?
Actually, is the singleton optimization legal? For immutable objects sure,
but for mutable ones it seems clearly incorrect.
It is a bit ugly either way. The real problem is that you would like the
control flow to be controlled by the generator of the elements, not the
consumer. Then you could avoid the extra test per loop.
More seriously, optimizing away the tuple construction is really important
especially if you use fold/unfold a lot. Then you end up tupling things all
the time.