From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p42FXpNh024791 for ; Mon, 2 May 2011 17:33:51 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnADAH/Ovk3VhjEVd2dsb2JhbACYI417FAEMCwsHESiIcbgShgAEkxIJigE X-IronPort-AV: E=Sophos;i="4.64,303,1301868000"; d="scan'208";a="107270418" Received: from ihsmtp01cons.lis.interhost.com ([213.134.49.21]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 May 2011 17:33:32 +0200 Received: from [192.168.1.64] ([178.166.9.223]) by ihsmtp01cons.lis.interhost.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 2 May 2011 16:33:18 +0100 Message-ID: <4DBECEC8.8010108@inescporto.pt> Date: Mon, 02 May 2011 16:33:28 +0100 From: Hugo Ferreira User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: Gabriel Scherer CC: David MENTRE , =?ISO-8859-1?Q?=C7agdas_Bo?= =?ISO-8859-1?Q?zman?= , caml-list users References: <4DBEB653.3000002@inescporto.pt> <4DBEBD4A.7070406@inescporto.pt> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 02 May 2011 15:33:18.0610 (UTC) FILETIME=[42F64720:01CC08DE] Subject: Re: [Caml-list] Forcing a Map type: setting the value type David and Gabriel, On 05/02/2011 04:15 PM, Gabriel Scherer wrote: > My basic idea was to re-export Map using a constrained type. With David > Mentre's insight that only map-producing functions need to be coerced, I > have the following proposal: > > module type MonoMap = sig > include Map.S > type elt > val empty : elt t > val singleton : key -> elt -> elt t > val of_enum : (key * elt) Enum.t -> elt t > end > > module IntMap > : MonoMap with type key = int with type elt = int > = struct > include Map.Make(Int) > type elt = int > end > Thank you, Hugo F. > On Mon, May 2, 2011 at 4:46 PM, David MENTRE > wrote: > > Hello Hugo, > > 2011/5/2 Hugo Ferreira >: > > Maybe I did not express myself correctly. > > The above would also work with any other type for the > > parameter 'a. I want only integers for it. So: > > > > # let m = IntMap.empty;; > > Just do: > > # let m : int IntMap.t = IntMap.empty;; > > The " : int IntMap.t" type annotation restricts the default "'a > IntMap.t" of IntMap.empty. > > > # let m = IntMap.add 1 "42" m;; > > Then: > > # let m = IntMap.add 1 "42" m;; > Characters 26-27: > let m = IntMap.add 1 "42" m;; > ^ > This expression has type int IntMap.t but is here used with type > string IntMap.t > > > Best regards, > david > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > >