Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 compare=Pervasives.compare?  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 set.ml 
 > and modifying it?

Unfortunately, no. 

Note that when duplicating the code from set.ml, 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
  end
  module type S = sig
    type 'a elt
    type 'a t
    ...
  end
  module Make(Ord: OrderedType): (S with type 'a elt = 'a Ord.t)

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

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

Best regards,
-- 
Jean-Christophe