From: Hugo Ferreira <hmf@inescporto.pt>
To: "Çagdas Bozman" <cagdas@bozman.fr>
Cc: caml-list users <caml-list@inria.fr>
Subject: Re: [Caml-list] Forcing a Map type: setting the value type
Date: Mon, 02 May 2011 15:18:50 +0100 [thread overview]
Message-ID: <4DBEBD4A.7070406@inescporto.pt> (raw)
In-Reply-To: <BANLkTikn+xxaBeBC0nW0=XFibbcwbC-VFQ@mail.gmail.com>
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 = <abstr>
> # let m = IntMap.add 1 42 m;;
> val m : int IntMap.t = <abstr>
> # 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 <hmf@inescporto.pt <mailto:hmf@inescporto.pt>>
>
> 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 <cagdas@bozman.fr <mailto:cagdas@bozman.fr>>
>
next prev parent reply other threads:[~2011-05-02 14:18 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 [this message]
2011-05-02 14:46 ` David MENTRE
2011-05-02 15:15 ` Gabriel Scherer
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=4DBEBD4A.7070406@inescporto.pt \
--to=hmf@inescporto.pt \
--cc=cagdas@bozman.fr \
--cc=caml-list@inria.fr \
/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