English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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 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
  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  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

Best regards,