Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: first class, recursive, mixin modules (was: RE: first class m odules)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Rogoff <bpr@b...>
Subject: RE: first class, recursive, mixin modules (was: RE: first class m odules)
On Fri, 12 Jan 2001, Claudio Russo wrote:
> I wasn't quite sure of your intention, but I did get the attached code
> to work in Mosml (it includes a port of the Ocaml libraries and a
> fleshed out implementation of your idea).

Cool! OK, now Alain has at least one example of a practically useful case
handled by your scheme :-). I suspect that this problem bites lots of ML 
programmers, and a fix is eagerly desired by at least two OCaml
programmers. Congratulations on making this work, the millenium is
starting off on a great note already!

> Unfortunately, this only works in an internal release of Moscow, because
> of a (known) bug in the current distribution. 

Well, even more unfortunately, a fix in Mosml doesn't help me unless you
change to Mosocaml. I couldn't switch to SML even if I wanted to, and I 
don't want to! Hopefully the OCaml Implementors (you guys are even
capitalized now) will "borrow back" the Mosml improvements into OCaml. 

> For the record, your functor application Make(Ord)is fine because it is
> applied to a local, already defined structure.
[...snip...]
> An application like Make(T.Ord), through the forward reference, would
> raise the Bind exception, because T (and T.Ord) is 
> undefined at that point (although Ord is).

That's no problem for me. Dave, in the case you mentioned, do you think
this would this be problematic? I couldn't guess from your description.

-- Brian 

> > -----Original Message-----
> > From: Brian Rogoff [mailto:bpr@best.com]
> > Sent: 11 January 2001 20:01
> > To: Dave Berry
> > Cc: Claudio Russo; Alain Frisch; Caml list
> > Subject: RE: first class, recursive, mixin modules (was: RE: 
> > first class
> > m odules)
> > 
> > 
> > My "litmus test" for recursive modules is that it fixes the well known
> > problem with expressing what OO folk call the Composite pattern,
> > essentially a recursively defined collection type with a leaf/node
> > relationship. Here is an approxmation of what I want to do in 
> > "faux-Mosml
> > with OCaml libraries". Forgive my errors, I don't use SML. The idea
> > should be clear. 
> > 
> > signature COMPOSITE = 
> >     rec(X : sig structure CompositeSet : sig type t end end) 
> >     sig structure Composite : 
> >                   sig 
> >                     datatype t = 
> >                       { data : int ; children : X.CompositeSet.t }
> >                   end
> >         structure CompositeSet : (Set.S where type elt = Composite.t) 
> >     end;
> > 
> > structure T = rec(X : COMPOSITE) 
> >   struct 
> > 	structure Composite = 
> >           struct 
> >             datatype t = { data : int ; children : X.CompositeSet.t }
> >           end
> >         structure Ord : Set.OrderedType = 
> >           struct 
> >             type t = Composite.t 
> >             let compare = Pervasives.compare
> >           end
> > 	structure CompositeSet = Set.Make(Ord)  
> >     end
> > 
> > This is syntactically heavy, but better than the 
> > parameterization trick 
> > needed now, and I'd be satisfied. I do need to do that functor
> > instantiation, so if you can't do it in Mosml it needs to be added. 
> > 
> > I agree that the first-class module extension is useful on 
> > its own too,
> > but in my own programming the problem I mention above arises 
> > frequently
> > enough that I consider this a flaw of (current) ML style 
> > modules. Every 
> > language has flaws but since OCaml is so close to perfection 
> > every flaw 
> > seems large ;-). 
> > 
> > -- Brian