[MLton] printf via fold

Stephen Weeks MLton@mlton.org
Sat, 10 Sep 2005 07:13:04 -0700


> There is a problem in the above implementation of step0. Namely, the
> case expression restricts the type of the output (value of the case
> expression) to be the same as the type of the input (e).

Whoops, good catch.  It's always surprising to me when there's a
difference in meaning between

   case e of E e' => E e' | ...

and

   case e of E _ => e | ...

> The rest is just an implementation of FoldHandle with the case expression
> replaced by an application of either. I also use Fold.step0 to simplify the
> implementation.

Nice.  One minor simplification is to remove the $ from step0.

  fun step0 h = Fold.step0 (either (fn v => eval (fn () => h v), RIGHT))

> (The version I have in my utility library is slightly different, though.
> I don't use a {finish, handler} record and I use currying in step1.)

Darn.  I thought we agreed that currying in step1 doesn't make sense
(as opposed to in the MakeFold functions, where it does).