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