From: Christophe Troestler <Christophe.Troestler@umons.ac.be>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] First class modules aliases
Date: Fri, 14 Feb 2014 08:23:52 +0100 [thread overview]
Message-ID: <20140214.082352.48621319473754158.Christophe.Troestler@umons.ac.be> (raw)
Hi,
I have encoutered several annoyances with module aliasing in the
context of first class modules. For example, if I declare
module type A = sig type t end
type 'a a = (module A with type t = 'a)
module type IA = A with type t = int
type ia = (module IA)
then I expect the types “int a” and “ia” to be equivalent but this is
not the case:
let f (a: int a) = (a : ia)
gives the error
This expression has type int a = (module A with type t = int)
but an expression was expected of type ia = (module IA)
That's unfortunate because one may want to use the shortcut “IA” to
constraint various module types and still expect to be able to use the
general functions for “int a” on those.
Another example is:
module X = struct
module type T = sig type s end
type 'a t = (module T with type s = 'a)
let id (x: int t) = x
end
let f (x: int X.t) = x
module Y = struct
include X
let h x = f(id x)
end
To make it work, I basically have to perform by hand the aliasing that
“include X” should make:
module Y : sig type 'a t val h : int t -> int t end = struct
type 'a t = 'a X.t
let h x = f(X.id x)
end
This problem makes modularity more difficult.
Are the above problems that one has to learn to live with when using
first class modules or may we expect the type checker to be able to
cope with them in the future?
Best,
C.
next reply other threads:[~2014-02-14 7:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-14 7:23 Christophe Troestler [this message]
2014-02-14 8:57 ` Alain Frisch
2014-02-14 9:08 ` Jacques Garrigue
2014-02-14 9:22 ` Alain Frisch
2014-02-14 23:23 ` Jacques Garrigue
2014-02-14 9:39 ` Alain Frisch
[not found] ` <20140215.152342.1020588167010524975.Christophe.Troestler@umons.ac.be>
2014-02-15 15:05 ` [Caml-list] First class modules from C Alain Frisch
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=20140214.082352.48621319473754158.Christophe.Troestler@umons.ac.be \
--to=christophe.troestler@umons.ac.be \
--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).