[MLton] MLton.Vector.create

Henry Cejtin henry.cejtin@sbcglobal.net
Tue, 28 Mar 2006 13:59:21 -0600


Ah,  you  are right.  I hadn't thought about the elements having to be closed
over sub.

Re tabulate vs. a single initial value, I agree that I almost always tend  to
use the former, counting on MLton being able to optimize away the overhead in
the constant case.  On the other hand, having tabulate have access to sub and
update makes me nervous for some reason.

I  think  that  the  big problem is that what is legal and what isn't becomes
MUCH less syntactically clear  (although  I  agree  that  it  is  still  well
defined).   Before,  I just couldn't stash away the update function.  That is
usually trivial to see syntactically.  Now I have to think about what indices
I am allowed to use.

Unrelated  to  that, if I want to do what the old one did, I now have to test
in the second argument for getting the last value  as  the  curried  int  arg
(since  that  is  my  only  chance  to  whack  away  with a fully initialized
array/vector).

I think that even if you want to give the power to access the sub and  update
functions  in  the  tabulator,  you  still want to have a separate functional
argument, of type
    { sub: int -> 'a, update: int * 'a -> unit } -> unit
which gets applied just before returning the now-converted-to-vector  result.

Another  question: why is the tabulator curried?  I guess one answer would be
that just like the final folder wants a hook to be called last,  the  curried
tabulator  gives you a hook for something to be called first (and establish a
scope as well).

Any way, to summarize:

    I completely agree that sub should continue to work after create returns.

    I  really  think  that  you  need an functional argument that lets you do
        stuff after the array is initialized (and which can still do  updates
        and subs).

    Other  than  that,  it is definitely feeling way more hacky with this new
        interface than it did before (and I admit that it was  epsilon  hacky
        already).  It is strictly more powerful, but just doesn't feel at all
        right to me.

    One stylistic change, I always use Limit or Lim for things that are  just
        past the last one you can hit, so I would change subMax and updateMax
        to subLim and updateLim.