caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* modules and recursive types
@ 2000-11-04  5:29 Julian Assange
  2000-11-07 13:27 ` Sven LUTHER
  0 siblings, 1 reply; 2+ messages in thread
From: Julian Assange @ 2000-11-04  5:29 UTC (permalink / raw)
  To: caml-list; +Cc: proff


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?

Cheers,
Julian.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: modules and recursive types
  2000-11-04  5:29 modules and recursive types Julian Assange
@ 2000-11-07 13:27 ` Sven LUTHER
  0 siblings, 0 replies; 2+ messages in thread
From: Sven LUTHER @ 2000-11-07 13:27 UTC (permalink / raw)
  To: Julian Assange; +Cc: caml-list

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-11-08 17:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-04  5:29 modules and recursive types Julian Assange
2000-11-07 13:27 ` Sven LUTHER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).