From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p42FGHC2023921 for ; Mon, 2 May 2011 17:16:17 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjACAFPKvk3RVdQ2kGdsb2JhbACYI4ZQAYchCBQBAQEBCQkNBxQEIYhxnSqKfIIqhBM0iF4BAQMGhXoEgg2MbIo6O4Mv X-IronPort-AV: E=Sophos;i="4.64,303,1301868000"; d="scan'208";a="94234986" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 May 2011 17:16:11 +0200 Received: by mail-vw0-f54.google.com with SMTP id 18so8247966vws.27 for ; Mon, 02 May 2011 08:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=McPLyQfzP8Y58H7mFWEAFZVPGovLsHnO70amBKg+Xyg=; b=e+2A3lVKRRgHwpiH6fFMS1yUKF33rCQmCs9FAfX2f7CA7Uuz0k2D6SY4/GeR96df+N 3BwfNEA+En1H5xfjC3Dxg3veEZuIHpbfKIIFoxybE9iTBPNTe7nKnw9fS02N5r/Z8LbX MyP3hKqR/APX+vDz4KwkEBHR+9yw8Ajzk9Qu8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=daacvptGpgPPw9N/orXLDA5NYjz3mVzvq3O0frvd8oWhtOGLlekhk+0Unan4xR1NVD 8M6gyUAuVs1Yr136OOd5ICgUyTBr1+/XRlnbmZ0upOEsqd77qpFmPO5YBc9pv73t4p/J HPTAHwMwnrGmriYClTDC1V/yRk/ipaTv038C0= Received: by 10.52.68.18 with SMTP id r18mr5864968vdt.82.1304349371109; Mon, 02 May 2011 08:16:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.114.5 with HTTP; Mon, 2 May 2011 08:15:51 -0700 (PDT) In-Reply-To: References: <4DBEB653.3000002@inescporto.pt> <4DBEBD4A.7070406@inescporto.pt> From: Gabriel Scherer Date: Mon, 2 May 2011 17:15:51 +0200 Message-ID: To: David MENTRE Cc: Hugo Ferreira , =?ISO-8859-1?Q?=C7agdas_Bozman?= , caml-list users Content-Type: multipart/alternative; boundary=20cf30780dc2ed8fb604a24c8097 Subject: Re: [Caml-list] Forcing a Map type: setting the value type --20cf30780dc2ed8fb604a24c8097 Content-Type: text/plain; charset=ISO-8859-1 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 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 > > --20cf30780dc2ed8fb604a24c8097 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable My basic idea was to re-export Map using a constrained type. With David Men= tre's insight that only map-producing functions need to be coerced, I h= ave the following proposal:

module type MonoMap =3D sig
=A0 inclu= de Map.S
=A0 type elt
=A0 val empty : elt t
=A0 val singleton : key -> elt = -> elt t
=A0 val of_enum : (key * elt) Enum.t -> elt t
end
<= br>module IntMap
=A0 : MonoMap with type key =3D int with type elt =3D i= nt
=A0 =3D struct
=A0=A0=A0 include Map.Make(Int)
=A0=A0=A0 type elt =3D int
end
On Mon, May 2, 2011 at 4:46 PM, David MENTRE <dmentre@lin= ux-france.org> wrote:
Hello Hugo,

2011/5/2 Hugo Ferreira <hmf@inescpo= rto.pt>:
> 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 =3D IntMap.empty;;

Just do:

=A0# let m : int IntMap.t =3D IntMap.empty;;

The " : int IntMap.t" type annotation restricts the default "= ;'a
IntMap.t" of IntMap.empty.

> # let m =3D IntMap.add 1 "42" m;;

Then:

=A0# let m =3D IntMap.add 1 "42" m;;
Characters 26-27:
=A0let m =3D IntMap.add 1 "42" m;;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^
This expression has type int IntMap.t but is here used with type
=A0string IntMap.t


Best regards,
david

--
Caml-list mailing list. =A0Subscri= ption 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


--20cf30780dc2ed8fb604a24c8097--