From: Hugo Ferreira <hmf@inescporto.pt>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: "David MENTRE" <dmentre@linux-france.org>,
"Çagdas Bozman" <cagdas@bozman.fr>,
"caml-list users" <caml-list@inria.fr>
Subject: Re: [Caml-list] Forcing a Map type: setting the value type
Date: Mon, 02 May 2011 16:33:28 +0100 [thread overview]
Message-ID: <4DBECEC8.8010108@inescporto.pt> (raw)
In-Reply-To: <BANLkTin5CSbi6H3ax9ZmWz5V7H4vt7c+mA@mail.gmail.com>
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 <dmentre@linux-france.org
> <mailto:dmentre@linux-france.org>> wrote:
>
> Hello Hugo,
>
> 2011/5/2 Hugo Ferreira <hmf@inescporto.pt <mailto:hmf@inescporto.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 = 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
>
>
prev parent reply other threads:[~2011-05-02 15:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 13:49 Hugo Ferreira
[not found] ` <BANLkTikn+xxaBeBC0nW0=XFibbcwbC-VFQ@mail.gmail.com>
2011-05-02 14:18 ` Hugo Ferreira
2011-05-02 14:46 ` David MENTRE
2011-05-02 15:15 ` Gabriel Scherer
2011-05-02 15:33 ` Hugo Ferreira [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DBECEC8.8010108@inescporto.pt \
--to=hmf@inescporto.pt \
--cc=cagdas@bozman.fr \
--cc=caml-list@inria.fr \
--cc=dmentre@linux-france.org \
--cc=gabriel.scherer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox