caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Sheets <sheets@alum.mit.edu>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] First-class Functor Forgetting for Free
Date: Sun, 11 Aug 2013 02:55:16 +0100	[thread overview]
Message-ID: <CAAWM5TyT4kryhLbDzsNHyLw76QpWFzBXHR4+Vf9bSwKGy16-=Q@mail.gmail.com> (raw)

What issue prevents functions over first-class modules from forgetting
the first-class modules' type constraints?

That is, given:

###############

module type D = sig
  type t

  val x : t
  val f : t -> int
end

module type C = sig
  val q : int
end

module F(X : D) : C = struct
  let q = X.(f x)
end

let f x =
  let module X = (val x : D) in
  let module Q = struct
    let q = X.(f x)
  end in
  (module Q : C)

let x =
  let module X = struct
    type t = int

    let x = 2
    let f x = x * 3
  end in
  (module X : D with type t = int)

;;
let module X = (val x : D with type t = int) in
let module M = F(X) in
(* let x = (module (val x : D with type t = int) : D) in*)
let module M' = (val f x : C) in

Printf.printf "M.q  is %d\n%!" M.q;
Printf.printf "M'.q is %d\n%!" M'.q;
()

###############

Why must I uncomment (* let x = (module (val x : D with type t = int)
: D) in*) to compile?

I understand why structural subtyping requires a module cast but I
don't see why type relaxation would.
I looked at the generated assembly and this line seems to disappear.

Why is it needed?

Thanks,

David

             reply	other threads:[~2013-08-11  1:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-11  1:55 David Sheets [this message]
2013-08-11  7:53 ` Andreas Rossberg
2013-08-11 13:29   ` David Sheets
2013-08-11 14:32     ` Andreas Rossberg
2013-08-11 14:58       ` Leo White
2013-08-12 11:01         ` Andreas Rossberg
2013-08-12 11:37           ` Leo White
2013-08-12 12:15             ` Andreas Rossberg
2013-08-12 13:06               ` Leo White
2013-08-12 14:15                 ` Andreas Rossberg
2013-08-12 15:17                   ` Leo White
2013-08-12 16:08                     ` Andreas Rossberg
2013-08-12 16:46                       ` Leo White
2013-08-13 11:22                         ` Andreas Rossberg

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='CAAWM5TyT4kryhLbDzsNHyLw76QpWFzBXHR4+Vf9bSwKGy16-=Q@mail.gmail.com' \
    --to=sheets@alum.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).