I have often wanted something like the following:
open Core
(* K.t -> V.t *)
type t = (K.t, V.t, K.comparator_witness) Map.t
include Map.Make(K)
Unfortunately, the include statement fails because Map.Make(K)
defines
type 'v t = (K.t, 'v, K.comparator_witness) Map.t
but the module can only contain a single definition of the type t
.
The usual way around this is to use destructive substitution – except in this case we want to substitute the monomorphic
type t = (K.t, V.t, K.comparator_witness) Map.t
for the polymorphic type
type 'v t = (K.t, 'v, K.comparator_witness) Map.t
Is there any way to achieve this?
Here is what I have tried:
open Core
type t = (Int.t, String.t, Int.comparator_witness) Map.t
include (Map.Make_using_comparator(Int) : Map.S
with type Key.t = Int.t
with type Key.comparator_witness = Int.comparator_witness
with type _ t := t)
This fails with
Error: In this `with' constraint, the new definition of t
does not match its original definition in the constrained signature:
Type declarations do not match:
type _ t = t
is not included in
type 'a t =
(Key.t, 'a, Key.comparator_witness) Core_kernel__.Map_intf.Map.t
File "src/map_intf.ml", line 300, characters 2-86:
Expected declaration
I have also tried
open Core
type _ t0 = (Int.t, String.t, Int.comparator_witness) Map.t
include (Map.Make_using_comparator(Int) : Map.S
with type Key.t = Int.t
with type Key.comparator_witness = Int.comparator_witness
with type 'a t := 'a t0)
which fails with a very similar error.