caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Unpacked module parameterized type escaping
@ 2013-04-18 17:12 John Carr
  2013-04-18 20:11 ` Markus Mottl
  0 siblings, 1 reply; 2+ messages in thread
From: John Carr @ 2013-04-18 17:12 UTC (permalink / raw)
  To: caml-list


I have a function of two arguments:

1. A packed module implementing Map.S.

2. A value of the module's Map.S.t.

I can't find a way to prevent a "type constructor ... would escape its
scope" error.

I'm running into this limitation from the ocaml manual:

"The package-type syntactic class appearing in the (module package-type)
type expression and in the annotated forms represents a subset of module
types. This subset consists of named module types with optional
constraints of a limited form: only non-parametrized types can be
specified."

The type I want to constrain is parameterized: +'a Map.S.t.

Can I get this code to type check?

(* val make_module : unit -> (module Map.S with type key = int) *)
let make_module () =
  let module K = struct
    type t = int
    let compare = compare
  end
  in
    (module Map.Make(K) : Map.S with type key = int)

let is_empty m v =
  let module M = (val m : Map.S with type key = int) in
    M.is_empty v

(* This fails because (type mt) can not be unified with +'a Map.S.t.

let is_empty (type mt) m v =
  let module M = (val m : Map.S with type key = int and type t = mt) in
    M.is_empty v *)

(* This invalid syntax is approximately what I want:

let is_empty (type '+a mt) m v =
  let module M = (val m : Map.S with type key = int and type 'a t = 'a mt) in
    M.is_empty v
*)  

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-18 20:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-18 17:12 [Caml-list] Unpacked module parameterized type escaping John Carr
2013-04-18 20:11 ` Markus Mottl

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).