From: "Andreas Rossberg" <AndreasRossberg@web.de>
To: "Josh Berdine" <berdine@dcs.qmul.ac.uk>,
"'ocaml ml'" <caml-list@inria.fr>
Subject: Re: [Caml-list] type aliases and recursive modules
Date: Tue, 15 May 2007 19:40:55 +0200 [thread overview]
Message-ID: <01c201c79718$310774d0$16b2a8c0@wiko> (raw)
In-Reply-To: <02d701c79712$0fbb09f0$2f311dd0$@qmul.ac.uk>
"Josh Berdine" <berdine@dcs.qmul.ac.uk>:
> #
> module rec A : sig
> type t = It of ASet.t
> val compare : t -> t -> int
> val get : t -> ASet.t
> end = struct
> type t = It of ASet.t
> let compare = compare
> let get = function It(x) -> x
> end
>
> and ASet : sig
> type t
> val get_its_elements : t -> A.t list
> end = struct
> module C = Set.Make(A)
> type t = C.t
> let get_its_elements x = C.elements (A.get (C.choose x))
> end
>
> Characters 350-370:
> let get_its_elements x = C.elements (A.get (C.choose x))
> ^^^^^^^^^^^^^^^^^^^^
> This expression has type ASet.t but is here used with type
> C.t = Set.Make(A).t
You are suffering from the "double vision" problem. This arises when you
have a recursive module with an abstract type and attempt to cross the
abstraction boundary recursively. The type system does not make the abstract
type recursively transparent. Here is a simpler example:
# module rec A : sig type t val f : t -> t end =
struct type t = int let f (x : t) = A.f x end;;
This expression has type t = int but is here used with type A.t
You cannot do that in current Ocaml. The only way to avoid this problem is
by making the type t transparent in the ascribed signature.
This problem actually is not straightforward to address on the
type-theoretic level, and one of the reasons why recursive modules are
pretty much an open research topic.
Hope this helps,
- Andreas
prev parent reply other threads:[~2007-05-15 17:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-15 15:40 Josh Berdine
2007-05-15 16:29 ` [Caml-list] " Philippe Wang
2007-05-15 16:56 ` Josh Berdine
2007-05-15 17:11 ` Philippe Wang
2007-05-15 17:40 ` Andreas Rossberg [this message]
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='01c201c79718$310774d0$16b2a8c0@wiko' \
--to=andreasrossberg@web.de \
--cc=berdine@dcs.qmul.ac.uk \
--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