caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: David MENTRE <dmentre@linux-france.org>
Cc: "Hugo Ferreira" <hmf@inescporto.pt>,
	"Ç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, 2 May 2011 17:15:51 +0200	[thread overview]
Message-ID: <BANLkTin5CSbi6H3ax9ZmWz5V7H4vt7c+mA@mail.gmail.com> (raw)
In-Reply-To: <BANLkTik_rdhPLVSDfTOFaKa6mb=3E0OO3w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]

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 <dmentre@linux-france.org>wrote:

> Hello Hugo,
>
> 2011/5/2 Hugo Ferreira <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
>
>

[-- Attachment #2: Type: text/html, Size: 2402 bytes --]

  reply	other threads:[~2011-05-02 15:16 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 [this message]
2011-05-02 15:33         ` Hugo Ferreira

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=BANLkTin5CSbi6H3ax9ZmWz5V7H4vt7c+mA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=cagdas@bozman.fr \
    --cc=caml-list@inria.fr \
    --cc=dmentre@linux-france.org \
    --cc=hmf@inescporto.pt \
    /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;
as well as URLs for NNTP newsgroup(s).