[MLton] Structures inside a function?
Matthew Fluet
fluet@cs.cornell.edu
Fri, 21 Jan 2005 11:18:13 -0500 (EST)
>
> > > 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 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).
I suspect that you really want a whole family of functors:
functor GroupOps (structure G : GROUP) = ...
functor GroupOpsPercent (structure G : GROUP) = ...
functor GroupOpsDollar (structure G : GROUP) = ...
functor GroupOpsHash (structure G : GROUP) = ...
If you are in a situation where you are only working with one group and
the usual definitions of the arithmetic ops are unnecessary, use GroupOps.
If you are in a situation where you are working with multiple groups,
use GroupOpsPercent and GroupOpsDollar to get two sets of (distinguished)
functions.