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: Mon, 24 Dec 2007 12:44:02 +0100 [thread overview]
Message-ID: <476F9B82.2060103@dravanet.hu> (raw)
In-Reply-To: <476E6FB7.6040100@dravanet.hu>
Márk S. Zoltán wrote:
> Behold the following code snippet:
>
> 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 scandalous : Aleph.t
> end =
> struct
> type t = Aleph.t list
> let scandalous = Aleph.Tag((* HERE BE DRAGONS *) [])
> end
>
> The compiler complains that the empty list after HERE BE DRAGONS has
> type 'a list but it is used with type Beth.t. I'd expect the compiler
> to discover that those types can be unified via 'a == Aleph.t, since
> as far as I can tell, all necessary facts are visible at that point.
> Replacing "Beth : sig type t ..." with "Beth : sig type t = Aleph.t
> list ..." does away with the error, but I would very much like to keep
> Beth.t an opaque type. Is this an intended behavior? And if it is
> intended, is there a way to tell the compiler what I really want it to
> do?
>
> Thanks in advance for any help.
>
> Z-
The plot thickens. The following code provokes an error message stating
explicitly that type t in Beth is not the same as Beth.t:
----------------------
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 a_beth_t_value : t
val scandalous : Aleph.t
end =
struct
type t = Aleph.t list
let a_beth_t_value = ([] : t)
let scandalous = Aleph.Tag(a_beth_t_value)
end
----------------------
$ ocamlc -i Anomaly.ml
File "Anomaly.ml", line 18, characters 33-49:
This expression has type t = Aleph.t list but is here used with type Beth.t
---------------------
The error message references the mention of a_beth_value in the let
scandalous ... line. The ([] : t) construct in the previous line was
necessary to trigger the 'This expression has type t = Aleph.t list ...'
message, since a bare [] only triggers "This expression has type Aleph.t
list but ...", without an indication that it knows that type t is
Aleph.t list.
However, reexporting a_beth_t_value from Aleph satisfies the compiler:
--------------------
module rec Aleph :
sig
type t = Tag of Beth.t
val a_reexported_beth_t_value : Beth.t
end =
struct
type t = Tag of Beth.t
let a_reexported_beth_t_value = Beth.a_beth_t_value
end
and Beth :
sig
type t
val a_beth_t_value : t
val scandalous : Aleph.t
end =
struct
type t = Aleph.t list
let a_beth_t_value = []
let scandalous = Aleph.Tag(Aleph.a_reexported_beth_t_value)
end
--------------------
$ ocamlc -i Anomaly.ml
module rec Aleph :
sig type t = Tag of Beth.t val a_reexported_beth_t_value : Beth.t end
and Beth : sig type t val a_beth_t_value : t val scandalous : Aleph.t end
--------------------
So far it sounds like the compiler acknowledges there is a type Beth.t
and identifies it with type t in the sig of Beth, but fails to make the
connection between this type and the Aleph.t list type expression inside
the struct of Beth. But even that is only true if the type expression in
question uses a built-in list; if I replace it with an algebraic type
implementing my own list, even the original example starts working.
-------------------
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 scandalous : Aleph.t
end =
struct
type t = Cons of Aleph.t * t | Nil
let scandalous = Aleph.Tag(Nil)
end
-----------------
$ ocamlc -i Anomaly.ml
module rec Aleph : sig type t = Tag of Beth.t end
and Beth : sig type t val scandalous : Aleph.t end
-----------------
This is a bug, isn't it?
Cheers
Z-
next prev parent reply other threads:[~2007-12-24 11:44 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" [this message]
2007-12-27 23:13 ` "Márk S. Zoltán"
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=476F9B82.2060103@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