From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 7DF77BC57 for ; Mon, 20 Sep 2010 21:02:59 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.56,395,1280700000"; d="vcf'?scan'208";a="68049893" Received: from vpn-rocq-144.inria.fr (HELO [127.0.0.1]) ([128.93.42.144]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 20 Sep 2010 21:02:59 +0200 Message-ID: <4C97AFE2.9000809@inria.fr> Date: Mon, 20 Sep 2010 21:02:58 +0200 From: Dumitru Potop-Butucaru User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] How can I set a type parameter of Map.Make(X) ? References: <4C97714A.6050403@inria.fr> <4C97991F.7030503@inria.fr> <4C97A0BF.1020003@ens-lyon.org> In-Reply-To: <4C97A0BF.1020003@ens-lyon.org> Content-Type: multipart/mixed; boundary="------------080405050607080609020304" X-Spam: no; 0.00; foo:01 mli:01 val:01 val:01 bool:01 bool:01 iter:01 foo:01 int's:01 browsed:01 beginner's:01 ocaml:01 bug:01 beginner's:01 ocaml:01 X-Attachments: cset="utf-8" name="dumitru_potop_butucaru.vcf" name="dumitru_potop_butucaru.vcf" This is a multi-part message in MIME format. --------------080405050607080609020304 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Yes, but this involves duplicating code, and I really hate to duplicate code, even in interfaces. To also answer Ashish: I want to define an interface to modules where I use a very specific kind of map. Of course, I could leave Map.Make polymorphic, but that is a different module type than the one I want to use to represent my theory. Yours, Jacky On 20/09/2010 19:58, Martin Jambon wrote: > Dumitru Potop-Butucaru wrote: >> Actually, I was looking for a way to specialize a whole module, >> not just the associated type (**this** I knew how to do). >> I would like to write something like: >> >> include module type of Set.Make(String) with 'a= int >> >> Is this possible? > I don't know about such a shortcut, but the following works and the interface > is easier to use for a human: > > (* foo.mli *) > type key = string > type value = string > type map > val empty : map > val is_empty : map -> bool > val add : key -> value -> map -> map > val find : key -> map -> value > val remove : key -> map -> map > val mem : key -> map -> bool > val iter : (key -> value -> unit) -> map -> unit > val map : (value -> value) -> map -> map > val mapi : (key -> value -> value) -> map -> map > val fold : (key -> value -> 'a -> 'a) -> map -> 'a -> 'a > val compare : (value -> value -> int) -> map -> map -> int > val equal : (value -> value -> bool) -> map -> map -> bool > > > (* foo.ml *) > module M = Map.Make (String) > include M > type value = string > type map = string M.t > > > > Martin > > >> Yours, >> Jacky Potop >> >> >> >> >> On 20/09/2010 16:57, Ashish Agarwal wrote: >>> module M = Map.Make(String) >>> >>> type t = int M.t >>> >>> Type t is the type of maps from string's to int's. Or alternatively >>> write a >>> function that assumes 'a is some specific type: >>> >>> # let f m = M.fold (fun _ x y -> x + y) m 0;; >>> val f : int M.t -> int = >>> >>> >>> On Mon, Sep 20, 2010 at 10:35 AM, Dumitru Potop-Butucaru< >>> dumitru.potop_butucaru@inria.fr> wrote: >>> >>>> Hello, >>>> >>>> I'm certain most users here will consider the question trivially simple, >>>> but I browsed the documentation without finding a solution. >>>> >>>> The question is quite general: Given a polymorphic definition like >>>> Map.Make(X), where >>>> X is some module, how can I specialize its 'a type parameter, e.g. by >>>> setting it to Y, so that >>>> I have maps from X to Y ? >>>> >>>> Yours, >>>> Jacky Potop >>>> >>>> _______________________________________________ >>>> Caml-list mailing list. Subscription management: >>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >>>> Archives: http://caml.inria.fr >>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>>> >>>> >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs > --------------080405050607080609020304 Content-Type: text/x-vcard; charset=utf-8; name="dumitru_potop_butucaru.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dumitru_potop_butucaru.vcf" begin:vcard fn:Dumitru Potop-Butucaru n:Potop-Butucaru;Dumitru org:INRIA Rocquencourt;Project AOSTE adr:;;Domaine de Voluceau, BP 105;Le Chesnay;;F-78153;France email;internet:dumitru.potop_butucaru@inria.fr tel;work:+33-139.63.55.80 tel;fax:+33-139.63.51.93 x-mozilla-html:FALSE url:http://www.DumitruPotop.net version:2.1 end:vcard --------------080405050607080609020304--