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 p42EIl3T021543 for ; Mon, 2 May 2011 16:18:51 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgsEAPK8vk3VhjEVd2dsb2JhbACYIo16FAEMCwsHESiIcbc+hgAEkxIJigE X-IronPort-AV: E=Sophos;i="4.64,303,1301868000"; d="scan'208";a="107263653" Received: from ihsmtp01cons.lis.interhost.com ([213.134.49.21]) by mail1-smtp-roc.national.inria.fr with ESMTP; 02 May 2011 16:18:51 +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 15:18:37 +0100 Message-ID: <4DBEBD4A.7070406@inescporto.pt> Date: Mon, 02 May 2011 15:18:50 +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: =?ISO-8859-1?Q?=C7agdas_Bozman?= CC: caml-list users References: <4DBEB653.3000002@inescporto.pt> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 02 May 2011 14:18:37.0889 (UTC) FILETIME=[D43E8310:01CC08D3] Subject: Re: [Caml-list] Forcing a Map type: setting the value type On 05/02/2011 03:11 PM, Çagdas Bozman wrote: > I would use something like this : > > module IntMap = Map.Make (struct > type t = int > let compare = Pervasives.compare > end);; > > # let m = IntMap.empty;; > val m : 'a IntMap.t = > # let m = IntMap.add 1 42 m;; > val m : int IntMap.t = > # IntMap.find 1 m ;; > - : int = 42 > 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;; # let m = IntMap.add 1 "42" m;; should not work. R, Hugo F. > 2011/5/2 Hugo Ferreira > > > Hello, > > I would like to make a Map with the key = int and > and the value also equal to int. Is this possible? > The example below does not work. > > TIA, > Hugo F. > > > # module Domains : Map.S with type key = int > with type (+'a) t = int = Map.Make( Int );; > Error: Signature mismatch: > Modules do not match: > sig > type key = Int.t > type 'a t = 'a Map.Make(Int).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 > is not included in > sig > type key = int > type 'a t = int > 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 > Type declarations do not match: > type 'a t = 'a Map.Make(Int).t > is not included in > type 'a t = int > > > -- > 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 > > > > Best regards, > -- > Çagdas Bozman > >