caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Derek Dreyer" <dreyer.publicity@gmail.com>
To: "Stephen Weeks" <sweeks@sweeks.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] question on type checking
Date: Wed, 21 Mar 2007 10:51:53 -0500	[thread overview]
Message-ID: <db810ed70703210851o5ca0d4b4ia10da86a57201b79@mail.gmail.com> (raw)
In-Reply-To: <604682010703201120j54305a8dmf7174f434cedfa96@mail.gmail.com>

This appears to be a bug in the typechecker.  Perhaps a more obvious
instance of the problem is if, after the (top-level) definition of S
in your first example you write:

module T = S
let x = if true then T.A else S.A

This clearly should typecheck, but instead you get the error message:

> This expression has type S.t = F(S.Z).t but is here used with type
>   T.t = F(T.Z).t

Huh?  You mean S.t does not equal T.t when I just defined T = S?

The problem is precisely that the typechecker is not properly
selfifying (strengthening) the signature of S in processing "module T
= S".  When properly selfified, the signature of S (and thus also T)
should be

sig
  module Z : sig end
  module M : sig type t = F(S.Z) = A end
  type t = F(S.Z) = A end
end

but instead of F(S.Z), it's just doing F(Z).  This wouldn't be an
issue if the language tracked structure identities across renamings
(since S.Z and T.Z are clearly the same structure), but it doesn't.

In your second example, this bug didn't pop up because Z was not
named, so M.t could not be characterized precisely through an
applicative functor type of the form F(<something>).t.

In your third example, this bug didn't pop up because you didn't
rename the structure S (and hence tickle the signature strengthening
bug).

I'm guessing this bug should be easy to fix.

Derek

On 3/20/07, Stephen Weeks <sweeks@sweeks.com> wrote:
> Why does one of the programs below fail to type check while the other two minor
> variants succeed?  I would expect all three to succeed.
>
> ----------------------------------------------------------------------
> (* FAILS *)
> module F (Z : sig end) = struct
>  type t = A
> end
>
> module S = struct
>  module Z = struct end
>  module M = F (Z)
>  include M
> end
>
> let f x =
>  let module S = S in
>  match x with
>  | S.A -> ()
> ----------------------------------------------------------------------
> (* WORKS *)
> module F (Z : sig end) = struct
>  type t = A
> end
>
> module S = struct
>  module M = F (struct end)
>  include M
> end
>
> let f x =
>  let module S = S in
>  match x with
>  | S.A -> ()
> ----------------------------------------------------------------------
> (* WORKS *)
> module F (Z : sig end) = struct
>  type t = A
> end
>
> module S = struct
>  module Z = struct end
>  module M = F (Z)
>  include M
> end
>
> let f x =
>  match x with
>  | S.A -> ()
> ----------------------------------------------------------------------
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2007-03-21 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-20 18:20 Stephen Weeks
2007-03-21 15:51 ` Derek Dreyer [this message]
2007-03-22  1:13   ` [Caml-list] " Stephen Weeks
2007-03-22  4:32     ` Derek Dreyer
2007-03-26 14:24       ` Xavier Leroy

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=db810ed70703210851o5ca0d4b4ia10da86a57201b79@mail.gmail.com \
    --to=dreyer.publicity@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=sweeks@sweeks.com \
    /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).