Browse thread
Building a Set module for elements of a Map
-
Fabrice Marchant
- Jean-Christophe_Filliâtre
- Xavier Leroy
- Fabrice Marchant
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2008-06-26 (09:19) |
From: | Jean-Christophe_Filliâtre <Jean-Christophe.Filliatre@l...> |
Subject: | Re: [Caml-list] Building a Set module for elements of a Map |
Fabrice Marchant wrote: > Please consider a functor F that takes as input the output signature of a Map. > > Here is the only way I see to declare a Set module whose elements type are Map.S.key : > > module F ( M : Map.S ) = struct > module MKeySet = > Set.Make ( struct type t = M.key let compare = compare end ) > end > > The problem is to access the OrderedType that permitted to build the Map M. It seems to have disappeared inside the output Map signature S. So the trial of regeneration : > struct type t = M.key let compare = compare end > > It maybe exists a straightforward signature we could pick somewhere inside Map related modules ? > Moreover I'm afraid this "Ersatz" of signature based on _Pervasives_.compare is in some cases deficient, because different from original OrderedType of Map elements... Using Pervasives.compare instead of a user-defined comparison function may even be incorrect. (Suppose the intended comparison function should identify (x,y) and (y,x), for instance; obviously, Pervasives.compare will not.) A possible solution to your problem is to have functor F taking instead a module for keys as argument, and then to build module M inside F; thus it would look like: module F(K : OrderedType) = struct module M = Map.Make(K) module MKeySet = Set.Make(K) ... end Hope this helps, -- Jean-Christophe Filliâtre http://www.lri.fr/~filliatr/