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
'a Set?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-26 (08:25)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] 'a Set?

Mike Hamburg writes:
 > Is there any clean way to make a type 'a set, corresponding to Set.Make 
 > of a module with type t='a and  I'm trying 
 > to make a module which uses sets of arbitrary types of objects, and I 
 > don't want to have to make it a functor.

This is a recurrent question on this list.

 > Is there a clean way to do this without removing the code from 
 > and modifying it?

Unfortunately, no. 

Note that when duplicating the code from, you can either keep a
functorized code, with an additional type parameter:

  module type OrderedType = sig
    type 'a t
    val compare: 'a t -> 'a t -> int
  module type S = sig
    type 'a elt
    type 'a t
  module Make(Ord: OrderedType): (S with type 'a elt = 'a Ord.t)

or directly substitute for the comparison function
to get a polymorphic data structure (and no functor anymore):

  module AlphaSet : sig
    type 'a elt
    type 'a t

Best regards,