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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL 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 D9575BC6C for ; Mon, 30 Jul 2007 18:43:05 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6UGh5pN009674 for ; Mon, 30 Jul 2007 18:43:05 +0200 Received: by ug-out-1314.google.com with SMTP id o2so1075427uge for ; Mon, 30 Jul 2007 09:43:05 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=leEuOs9mm7U+i8jqN3HA39Frjn8DZrmbg2yVv+oK44Q2qTwYzqIFlvaqKZGtmvU96y4pyILRWowewgHiRwACGZoUe7xr+WvakQ/BJfdi8aGwhvmRFSyqNooO6Erpd7/+4atiwOd4qcCpvYqkJL+RUO+0/qwhMiZqHZszG0Z2jIg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=oAUqwgXBI2uy/nI/Ql1rteQO50rKuhF3s+HbUnoz5cLlm4IHzSYcYQGuV7DU07eCym/VmjmU9dUnpgyhRw9HpKIJiXyvDLH0CcwC8Iv3F/XsGRBhMpaI7kslcXBmqsSPbMS+F5SnseCTL9Q/VBM9FrCQdnB7QrzaORVlcEXN8sI= Received: by 10.78.145.5 with SMTP id s5mr1561706hud.1185813784982; Mon, 30 Jul 2007 09:43:04 -0700 (PDT) Received: by 10.78.158.5 with HTTP; Mon, 30 Jul 2007 09:43:04 -0700 (PDT) Message-ID: <4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com> Date: Mon, 30 Jul 2007 12:43:04 -0400 From: "Christopher L Conway" Sender: christopherleeconway@gmail.com To: skaller Subject: Re: [Caml-list] module interface? Cc: caml-list@inria.fr In-Reply-To: <1185782144.6753.13.camel@rosella.wigram> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1185777938.6753.7.camel@rosella.wigram> <9b415f950707300003t225273cfi9d2761359bf6a3be@mail.gmail.com> <1185782144.6753.13.camel@rosella.wigram> X-Google-Sender-Auth: aec133d3664575a1 X-Miltered: at discorde with ID 46AE1519.001 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 functor:01 sig:01 val:01 val:01 bool:01 bool:01 iter:01 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 The function Ord.compare is "dropped" (hidden, really) because it's not part of the module type Map.S. You could write your own functor that exposes it (note that "compare" is bound in Map.S to the function which compares two maps): # module type MyMapS = sig include Map.S val compare_keys : key -> key -> int end ;; module type MyMapS = sig type key type +'a t val empty : 'a t val is_empty : 'a t -> bool val add : key -> 'a -> 'a t -> 'a t val find : key -> 'a t -> 'a val remove : key -> 'a t -> 'a t val mem : key -> 'a t -> bool val iter : (key -> 'a -> unit) -> 'a t -> unit val map : ('a -> 'b) -> 'a t -> 'b t val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool val compare_keys : key -> key -> int end # module MyMap( Ord : Map.OrderedType ) = struct module M = Map.Make( Ord ) open M let compare_keys = Ord.compare end ;; module MyMap : functor (Ord : Map.OrderedType) -> sig module M : sig type key = Ord.t type 'a t = 'a Map.Make(Ord).t val empty : 'a t val is_empty : 'a t -> bool val add : key -> 'a -> 'a t -> 'a t val find : key -> 'a t -> 'a val remove : key -> 'a t -> 'a t val mem : key -> 'a t -> bool val iter : (key -> 'a -> unit) -> 'a t -> unit val map : ('a -> 'b) -> 'a t -> 'b t val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool end val compare_keys : Ord.t -> Ord.t -> int end Regards, Chris