caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] First-class Functor Forgetting for Free
@ 2013-08-11  1:55 David Sheets
  2013-08-11  7:53 ` Andreas Rossberg
  0 siblings, 1 reply; 14+ messages in thread
From: David Sheets @ 2013-08-11  1:55 UTC (permalink / raw)
  To: Caml List

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

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

end of thread, other threads:[~2013-08-13 11:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-11  1:55 [Caml-list] First-class Functor Forgetting for Free David Sheets
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

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