From: "\"Márk S. Zoltán\"" <zoltan.s.mark@dravanet.hu>
To: Caml Mailing List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Type visibility limitation in recursive modules
Date: Fri, 28 Dec 2007 00:13:24 +0100 [thread overview]
Message-ID: <47743194.1080801@dravanet.hu> (raw)
In-Reply-To: <476F9B82.2060103@dravanet.hu>
The problem only impacts types declared via parametrized type
constructors. To wit:
This does not work:
----------------------------------------
module rec Aleph : sig type t = Tag of Beth.t end =
struct type t = Tag of Beth.t end
and Beth : sig type t val v : Aleph.t end =
struct type t = Aleph.t list let v = Aleph.Tag([]) end
This does:
----------------------------------------
module rec Aleph : sig type t = Tag of Beth.t end =
struct type t = Tag of Beth.t end
and Beth : sig type t val v : Aleph.t end =
struct type t = Nil | Cons of Aleph.t * t let v = Aleph.Tag(Nil) end
And this does not:
----------------------------------------
type 'a mylist = Nil | Cons of 'a * 'a mylist
module rec Aleph : sig type t = Tag of Beth.t end =
struct type t = Tag of Beth.t end
and Beth : sig type t val v : Aleph.t end =
struct type t = Aleph.t mylist let v = Aleph.Tag(Nil) end
I have spent a few (dozen) hours debugging the compiler, and came to the
conclusion that the reason for this bug is that "strenghtening" does not
take place for Tconstr's. Tconstr types use their type_manifest fields
to hold a description of the type, while Tvariant types set it to None.
When the typing process of recursive modules reaches the strenghtening
phase, it dutifully avoids updating Tconstr's because their
type_manifest matches Some _, not None. As a result, Tconstr type
implementations cannot be hidden inside a recursive module.
This issue has other interesting variations, e.g. this works:
-----------------------------------------------
module type AT = sig type t val v : t end
module type S = sig module Aleph : AT end
module Make = functor(A : AT) ->
(struct module Aleph = A end : S with module Aleph = A)
module rec Al : AT =
struct type t = string let v = "v" end
and Ex : S with module Aleph = Al = Make(Al)
This doesn't:
-----------------------------------------------
module type AT = sig type t val v : t end
module type S = sig module Aleph : AT end
module Make = functor(A : AT) ->
(struct module Aleph = A end : S with module Aleph = A)
module rec Al : sig type t val v : t end (* NB: AT!!! *) =
struct type t = string let v = "v" end
and Ex : S with module Aleph = Al = Make(Al)
-----------------------------------------------------
File "Anomaly.ml", line 34, characters 9-33:
In this `with' constraint, the new definition of Aleph
does not match its original definition in the constrained signature:
Modules do not match: sig type t = Al.t end is not included in AT
The field `v' is required but not provided
----------------------------------------------------
Cheers
Z-
next prev parent reply other threads:[~2007-12-27 23:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-23 14:24 "Márk S. Zoltán"
2007-12-23 17:20 ` [Caml-list] " Peng Zang
2007-12-23 18:00 ` "Márk S. Zoltán"
2007-12-24 11:44 ` "Márk S. Zoltán"
2007-12-27 23:13 ` "Márk S. Zoltán" [this message]
2007-12-28 10:02 ` Keiko Nakata
2007-12-28 12:46 ` "Márk S. Zoltán"
2007-12-28 13:42 ` Keiko Nakata
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=47743194.1080801@dravanet.hu \
--to=zoltan.s.mark@dravanet.hu \
--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