[MLton] Monadic MLton.Vector.create with update

Stephen Weeks MLton@mlton.org
Thu, 30 Mar 2006 12:02:13 -0800


I think we all agree that one needs both a function that deals with
state explicitly, like unfold, and a function that deals with state
implicitly, like tabulate.  I'd make the following analogy, depending
on whether one is traversing or creating a structure.

	  implicit  explicit
          --------  --------
traverse  app       fold
create    tabulate  unfold

The question at hand is whether unfold should return then final
state.  It currently does not, but I think that is inconsistent with
unfold dealing with explicit state.  By analogy, should the type of
fold be

  val fold: 'a vector * 'b * ('a * 'b -> 'b) -> unit

Of course not.

And with unfold, just because it happens to create something along the
way doesn't change the fact that it has been accumulating an explicit
state.

Yes, I think it should clearly be changed from

  val unfold: int * 'b * ('b -> 'a * 'b) -> 'a vector

to

  val unfold: int * 'b * ('b -> 'a * 'b) -> 'a vector * 'b