Browse thread
module interface?
[
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: | -- (:) |
| From: | skaller <skaller@u...> |
| Subject: | Re: [Caml-list] module interface? |
On Mon, 2007-07-30 at 12:43 -0400, Christopher L Conway wrote: > On 7/30/07, skaller <skaller@users.sourceforge.net> wrote: > > On Mon, 2007-07-30 at 09:03 +0200, Benedikt Grundmann wrote: > > > module Drules : Map.S with type key = string > > > > So I discovered -- thanks! But hmm, this totally counter intuitive! > > > > You call Map.Make, but refer to Map.S. > > The supplied key is with > > > > type t = string > > > > but in the sig you use > > > > type key = string > > > > and finally the > > > > let compare = compare > > > > in the module is simply dropped. > > > > There is no example of this in the tutorial.. > > how would I every guess at the right solution? > > Map.Make has functor type (Map.OrderedType -> Map.S), so a module > Map.Make( Ord ) will have module type Map.S. Further, the type of > Map.Make has the restriction that Map.Make( Ord ).key = Ord.t. Since > the identity of Ord is hidden in your .mli, you have to expose it with > your own restriction (if it matters, which it probably does), thus: > > module Drules : Map.S with type key = string Yes, it is quite logical I'm sure, but that wasn't the issue so much as how someone would learn to use it, i.e. documentation and tutorial. The tutorial on functors skips over this by elaborating the signature of the resulting module. This looks cute in the tutorial, but is out of the question for even simple functors like Map.Make because they have far too many methods. If you try ocamlc -i .. it lists all those methods. Some years ago I actually used that in the *.mli file. It turned me off using functors. Later I learned: module Drules : Map.S with type key = string (and in fact already have several instances of that in my program, which I forgot about). Maybe Jon Harrop covers this well in his book? -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net