[MLton] Slightly simpler functional record update

Vesa Karvonen vesa.karvonen@cs.helsinki.fi
Sat, 13 Aug 2005 03:23:22 +0300


Quoting Stephen Weeks <sweeks@sweeks.com>:

> > > BTW, for easier typing, how about "M x esml-gen-fru-setter a b c"?
> > 
> > Sure, no problem. The idea of allowing a record pattern or a type is that
> > you can copy-paste it to the minibuffer.
> 
> Ah.  I'm not sure which is preferable then.  I guess it's easy enough
> to support both?

`esml-gen-fru-setter' now works with the following formats:

  id ... id
  {id, ..., id}
  {id : ty, ..., id : ty}

I also made the entire code template customizable, including the
four patterns used for matching/constructing tuple/record fields.
With the default settings, `M x esml-gen-fru-setter a b c' generates:

  fun set f =
      let
         fun t2r (v1, v2, v3) = {a = v1, b = v2, c = v3}
         fun r2t {a = v1, b = v2, c = v3} = (v1, v2, v3)
      in
         Records.wrapSet (Tuples.set3, t2r, t2r, r2t) f
      end

But it can be customized to generate (for example):

  val fru = let fun r (a, b, c) = {a = a, b = b, c = c}
            in fn f => wrapSet (set3, r, r, fn {a, b, c} => (a, b, c)) f
            end (* Generated by `M x esml-gen-fru-setter' *)

(Indentation is by `indent-region'.)

I can post the code or wait if/until I can commit it.

-Vesa Karvonen