From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 67DFEBC69 for ; Mon, 30 Jul 2007 19:13:18 +0200 (CEST) Received: from ipmail03.adl2.internode.on.net (ipmail03.adl2.internode.on.net [203.16.214.135]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6UHDFFF016475 for ; Mon, 30 Jul 2007 19:13:17 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJK3rUZ5LAMf/2dsb2JhbAAN X-IronPort-AV: E=Sophos;i="4.19,199,1183300200"; d="scan'208";a="123066574" Received: from ppp121-44-3-31.lns4.syd7.internode.on.net (HELO [192.168.1.201]) ([121.44.3.31]) by ipmail03.adl2.internode.on.net with ESMTP; 31 Jul 2007 02:43:13 +0930 Subject: Re: [Caml-list] module interface? From: skaller To: Christopher L Conway Cc: caml-list@inria.fr, Jon Harrop In-Reply-To: <4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com> References: <1185777938.6753.7.camel@rosella.wigram> <9b415f950707300003t225273cfi9d2761359bf6a3be@mail.gmail.com> <1185782144.6753.13.camel@rosella.wigram> <4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com> Content-Type: text/plain Date: Tue, 31 Jul 2007 03:13:12 +1000 Message-Id: <1185815592.8102.12.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46AE1C2B.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0200,:01 grundmann:01 sig:01 functor:01 orderedtype:01 ord:01 ord:01 mli:01 functors:01 functors:01 ocamlc:01 mli:01 sourceforge:01 sourceforge:01 wrote:01 On Mon, 2007-07-30 at 12:43 -0400, Christopher L Conway wrote: > On 7/30/07, skaller 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 Felix, successor to C++: http://felix.sf.net