Version française
Home     About     Download     Resources     Contact us    
Browse thread
modules and recursive types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sven LUTHER <luther@d...>
Subject: Re: modules and recursive types
On Sat, Nov 04, 2000 at 04:29:33PM +1100, Julian Assange wrote:
> 
> I'd like to do something like the following:
> 
> type snode = Empty | Snode of CharSet.t
> and
> module CharSet = Set.Make(struct type t = char * snode
> 		            let compare (x,_) (y,_) = Pervasives.compare x y
> 			  end)
> 
> That is define an inter-dependent typing relationship between two
> modules (although there is only one module here, the other can be
> viewed as the `null' module). Is this possible?  If not is there
> another way to achieve the effect?

Try using functors for that.

That said, i don't think it is possible to have mutually dependant
modules/functors/whatever. At leats i didn't manage to get some, but then
maybe it is possible, and i don't know how.

A workaround would be to do as follows :


type 'a snode = Empty | Snode of 'a 

module Charset = Set.Make (struct
  type t = One of char * t snode
  let compare ...
end

Notice the type t = One ...

You cannot have a recursive type without a variant constructor in it.

Hope this help, 

Friendly,

Sven Luther