Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: circular types?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2000-10-24 (05:13)
From: Brian Rogoff <bpr@b...>
Subject: Re: circular types?
On Mon, 23 Oct 2000, Tom Hirschowitz wrote:
> > Nope, no forwards in Ocaml. At some point, you'll have to tie the recursive 
> > knot with an "and". If the problem you're having is that "far away" means 
> > "in different modules" then you bump into the lack of recursive modules, 
> > IMO the biggest PITA with ML style modules.
> Hi, 
> I'm pleased to see I'm not working for nobody. 
> Actually I'm not working exactly on recursive modules, but rather on 
> mixin modules.
> Instead of defining your two modules and then link them, you would 
> create a new one with the holes filled.
> For instance, for Brain's example, you would write something like : 
> mixin A = 
>   mix 
>     deferred module CompositeSet : sig type t ... end
>     type composite = { data : string ; children : CompositeSet.t }
>   end;;
> mixin B = 
>   mix
>     deferred type composite
>     module CompositeSet = 
>       struct
>         type t = C of composite | D
>       end
>   end
> mixin C = A + B
> In fact, this one is too difficult for me right now, because it 
> relies on a mutual dependency between a type and a module.

I don't mind viewing modules as "the higher level" meaning that if you 
can have mutually recursive modules this is good enough since I just
encapsulate the type in a module. This is going to be a bit unnatural
sometimes because the Ocaml implemenation uses the top level module names 
specially but probably no big deal in practice. This is what Moscow ML
does; in OCamlized syntax the composite set looks like this I think 

module Composite = rec (Fwd : sig module ElemSet sig type t end end)
    module Elem = 
        type t = 
        { data : string
        ; children : Fwd.ElemSet.t
   module ElemSet = 
       type t = Elem.t Set.t

If you can support something similar that's fine with me, but if you think
you the direct type and module mutual recursion is workable that's even
better. And if you can do that then allowing mutual recursion between
classes and types also should be allowed. 

> Since I'm just beginning this, I would really be pleased by
> comments, suggestions or questions about it.

I also like that the syntax I show above consumed no more keywords. Just 
something to think about. 

-- Brian