[MLton] Structures inside a function?

Stephen Weeks MLton@mlton.org
Fri, 21 Jan 2005 07:34:51 -0800


> > functor GroupMulPercent(G : GROUP) = 
> >   struct
> >     val (op *%) = G.MUL
> >     val (op /%) = G.DIV
> >     val (op !%) = G.INV
> >     ...
...
> That is an interesting technique for quickly generating different 
> bindings.

I like it too.  Someone should add to the wiki this technique and the
others we've discussed.  I'd love to see progress on our MLton/SML
cookbook (perhaps start a new Cookbook page, linked from StandardML?).
I might even go further and drop the percents.

functor GroupOps (structure G: GROUP) =
   struct
      val op * = G.MUL
      val op / = G.DIV s
      val op ! = G.INV s
      ...
   end

The point being that you open the result of GroupOps in situations
where the usual definitions of the arithmetic ops might be
unnecessary, or it might be worth the conciseness to use qualified
identifiers for the usual functions (because they are in that context
unusual).