Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Carl Eastlund <ceastlund@janestreet.com>,
	OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Weird type error involving 'include' and applicative functors
Date: Tue, 24 Feb 2015 13:38:15 +0900	[thread overview]
Message-ID: <B9663FA4-652C-4D85-B1A5-104E4E5ABAD1@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAPFanBFiBB7qQT=3NCQv6TNN4ovw6nA3RJQ_yEKPhbLLyT1dOA@mail.gmail.com>

On 2015/02/15 19:26, Gabriel Scherer wrote:
> 
> That is one of the dark corners of the module system.
[…]
> I think this is due to the rather contorted way you define C first in
> the implementations and include it later, while in the signature first
> define t and then C. Note that the following signature, which is
> morally equivalent, accepts both implementations (and thus all the
> functors in your file):
>  sig
>    module C : S
>    type t = C.t
>  end

This is indeed the gist of the problem. Matching against

    sig
      type t
      module C : S with type t = t
    end

introduces a kind of mutual recursion: C.t is defined as t in the enclosing
signature, but t is C.t in the internal one. As a result we get a kind of
double-vision problem. Namely, t inside the internal C is Make(T).t (with
T the one inside C), but in the enclosing signature, the t inside C
is Make(C.T).t. While logically the T inside C and C.T are the same module,
the typing rule in Leroy's paper do not say anything like that.

σ : {1,...,m} 􏰀→ {1,...,n} for all i ∈ {1,...,m}, E;D1;...;Dn ⊢ Dσ(i) <: Di′
---------------------------------------------------------------------------------------
          E ⊢ sig D1;…;Dn end <: sig D1′ ;...;Dm′ end

The definition in the premise must match without extra equations.
Here module aliases do not help.
What could help would be to strengthen the definitions in the premise, so
that T would be converted to C.T. But I don't know whether this is sound
or not, since this is not part of the current theory.

Jacques Garrigue


> On Fri, Feb 13, 2015 at 10:40 PM, Carl Eastlund
> <ceastlund@janestreet.com> wrote:
>> This seems to be a compiler bug, but let me know if I've missed something.
>> The behavior I see is that Make_ok1 and Make_ok2 compile fine, but the very
>> similar functor Make_bad does not.  I get this compile error:
>> 
>> ========================================
>> 
>>      Error: Signature mismatch:
>>             Modules do not match:
>>               sig
>>                 module C : sig module T : sig  end type t = Make(T).t end
>>                 module T = C.T
>>                 type t = Make(T).t
>>               end
>>             is not included in
>>               sig type t module C : sig type t = t end end
>>             In module C:
>>             Modules do not match:
>>               sig module T : sig  end type t = Make(T).t end
>>             is not included in
>>               sig type t = C.t end
>>             In module C:
>>             Type declarations do not match:
>>               type t = Make(T).t
>>             is not included in
>>               type t = t
>> 
>> ========================================
>> 
>> And here is the code:
>> 
>> ========================================
>> 
>> module type S = sig type t end
>> module Make (M : sig end) : S = struct type t end
>> 
>> module Make_ok1 (M : sig end) : sig
>> 
>>  type t
>>  module A : S with type t = t
>> 
>> end = struct
>> 
>>  module A = struct
>>    include Make (struct end)
>>  end
>>  include A
>> 
>> end
>> 
>> module Make_ok2 (M : sig end) : sig
>> 
>>  type t
>>  module B : S with type t = t
>> 
>> end = struct
>> 
>>  module T = struct end
>>  module B = struct
>>    include Make (T)
>>  end
>>  include B
>> 
>> end
>> 
>> module Make_bad (M : sig end) : sig
>> 
>>  type t
>>  module C : S with type t = t
>> 
>> end = struct
>> 
>>  module C = struct
>>    module T = struct end
>>    include Make (T)
>>  end
>>  include C
>> 
>> end
>> 
>> ========================================
>> 
>> --
>> Carl Eastlund




  parent reply	other threads:[~2015-02-24  4:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 21:40 Carl Eastlund
2015-02-15 10:26 ` Gabriel Scherer
2015-02-16 18:03   ` Leo White
2015-02-17 21:40     ` Milan Stanojević
2015-02-19 18:21       ` Milan Stanojević
2015-02-19 18:23         ` Milan Stanojević
2015-02-24  4:38   ` Jacques Garrigue [this message]
2015-02-24  5:54     ` Jacques Garrigue

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=B9663FA4-652C-4D85-B1A5-104E4E5ABAD1@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=ceastlund@janestreet.com \
    --cc=gabriel.scherer@gmail.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