caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Hendrik Tews <tews@os.inf.tu-dresden.de>, caml-list@inria.fr
Subject: Re: [Caml-list] functor substitution gives error
Date: Wed, 8 Sep 2010 05:46:22 +0900	[thread overview]
Message-ID: <AANLkTikdon6AoahT-T0vVK_qK=4sPiZATLTn9JQX2xm=@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikXGkeY6Hd4FwHX2BeZOtF_mfgXDtOv==SbMMSO@mail.gmail.com>

On Mon, Sep 6, 2010 at 6:39 PM, Daniel Bünzli
<daniel.buenzli@erratique.ch> wrote:
> I think I just hit the same kind problem.
>
> This doesn't compile :
> ----
> module A : sig
>  type m
>  module M : sig
>    type t = m
>  end
> end = struct
>  module M = struct
>    module S = String
>    module Smap = Map.Make(S)
>    type t = int Smap.t
>  end
>  type m = M.t
> end
> ----
>
>  Type declarations do not match:
>         type t = int Smap.t
>       is not included in
>         type t = m
>
> However if I put S outside M, or if I specify the type of Smap it compiles :

At first, I thought this was a different problem, since there is no
"struct end".
However, this is actually the same problem.
To understand what is happening, you must look at what is inferred for
M.Smap.t in the different cases.

In the first and second case:
type 'a t = 'a Map.Make(S).t
If you specify the type of Smap it becomes:
type +'a t (just abstract)
or after strengthening (making types refer to their location)
type 'a t = 'a M.Smap.t

Here the problem is that S, by being only defined locally, plays the same
role as "struct end". The above type equation (in the first case) forbids
the stengthening of M.Smap.t, but later it has to be discarded because one
is not allowed to depend on a local module, meaning that we end up losing
a type equation. In the second case, this doesn't happen because S is no
longer local to M, and can be kept. And in the last one, by restricting the
type of Smap, you remove the type equation on Smap.t, allowing its
strengthening (only one type equation is allowed per type, so if there is
already one, strengthening cannot be done).

Since 3.12, there is a new compiler option, -no-app-funct, which disables
applicative functors, and as a result allows strengthening in more cases.
This solves your problem, but not Hendrik's, because his example
requires applicative functor to start with.

Jacques Garrigue

[Your 2 other versions]
> ----
> module A : sig
>  type m
>  module M : sig
>    type t = m
>  end
> end = struct
>  module S = String
>  module M = struct
>    module Smap = Map.Make(S)
>    type t = int Smap.t
>  end
>  type m = M.t
> end
> ----
>
> ----
> module A : sig
>  type m
>  module M : sig
>    type t = m
>  end
> end = struct
>  module M = struct
>    module S = String
>    module Smap = (Map.Make(S) : Map.S with type key = S.t)
>    type t = int Smap.t
>  end
>  type m = M.t
> end
> ----
>
> Daniel


  reply	other threads:[~2010-09-07 20:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06  9:12 Hendrik Tews
2010-09-06  9:39 ` [Caml-list] " Daniel Bünzli
2010-09-07 20:46   ` Jacques Garrigue [this message]
2010-09-07 10:48 ` Jacques Garrigue
2010-09-07 13:32   ` Hendrik Tews
2010-09-07 13:54   ` Daniel Bünzli

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='AANLkTikdon6AoahT-T0vVK_qK=4sPiZATLTn9JQX2xm=@mail.gmail.com' \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    --cc=tews@os.inf.tu-dresden.de \
    /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).