]>
Hi
> 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:
I think this problem comes from the stdlib of OCaml. We have:
1) For the Hashtable
type ('a, 'b) t
and
val length : ('a, 'b) t -> int
and
module type S = sig
type key
type 'a t
.... end
2) For the Map
module type S = sig
type key
type +'a t
end
3) For the Set
module type S = sig
type elt
type t
val cardinal : t -> int
end
This is hard to understand why the signatures of those modules are so
differents. Why there is (for example) not for the set, this signature:
module type S = sig
type 'a elt
type 'a t
...
end ?
Furthermore there is no lenght/cardinal function for the Map. Note that
WeakHashtble have the function val count : t -> int, so three different
names for the same things. When I teach Ocaml, many students are lost with
this differences.
Best regards,
Frédéric Gava