caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Carr <jfc@MIT.EDU>
To: caml-list@inria.fr
Subject: [Caml-list] Unpacked module parameterized type escaping
Date: Thu, 18 Apr 2013 13:12:37 -0400	[thread overview]
Message-ID: <201304181712.r3IHCbSC023593@outgoing.mit.edu> (raw)


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

             reply	other threads:[~2013-04-18 17:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18 17:12 John Carr [this message]
2013-04-18 20:11 ` Markus Mottl

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=201304181712.r3IHCbSC023593@outgoing.mit.edu \
    --to=jfc@mit.edu \
    --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;
as well as URLs for NNTP newsgroup(s).