From: Alain Frisch <alain.frisch@lexifi.com>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Subtyping of first-class module types
Date: Fri, 16 Apr 2010 20:21:56 +0200 [thread overview]
Message-ID: <4BC8AAC4.40404@lexifi.com> (raw)
Dear caml-list,
During today's ocaml meeting, the question of whether first-class module
types could support subtyping was asked. I'd like to give a more
detailed answer here.
The explicit subtyping construction (e : t1 :> t2) could easily be
extended to support subtyping of the form
(module S with type t1 = ...) :> (module S)
that is, to forget some type annotations. One could also support
subtyping of the form:
(module S) :> (module S')
provided that S is a subtype of S' (as module types), and *moreover*
that the coercion from S to S' is the identity. The only real use I
could see for it is when S and S' refer to the equal module types but
they are just different names (in which case (module S) and module
(module S') cannot be unified). The reason to require the coercion S ~~>
S' to be trivial is that the explicit subtyping construction is assumed
to be a runtime no-op.
That said, it is not difficult to use subtyping of module types by hand
as in:
(module (val x : S) : S')
which works as soon as S is a subtype of S'. Concretly, the code
generated for this piece of code is simply the coercion from module type
S to module type S'. This also work to forget type annotations (in which
case the coercion is the identity).
Given how simple this construction is, I don't think it is worth
extending the ( :> ) relation to support module types in very limited cases.
Alain
reply other threads:[~2010-04-16 18:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4BC8AAC4.40404@lexifi.com \
--to=alain.frisch@lexifi.com \
--cc=caml-list@yquem.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