caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Arlen Cox <arlencox@gmail.com>
Cc: Mailing List OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Applicative Functor Madness
Date: Fri, 21 Sep 2018 14:54:32 +0900	[thread overview]
Message-ID: <1D5C88F1-E691-4124-BBC6-5DB71E00A716@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAHEcMuFcWMJ6Y4XeDAOcrx1Jdy+Ts0R0TGoK1Yg6JxcNJ5P8xg@mail.gmail.com>

On 2018/09/21 10:25, Arlen Cox wrote:
> 
> Are the actual rules of module equality documented somewhere in the OCaml manual?

It seems you found them. Unfortunately, the OCaml manual does not provide a formal specification of OCaml, and it sometimes omits some implementation details. In this case I think it suffices.

> It seems like Section 8.12 documents this (at least partially):
> 
> There are several restrictions on module-path:
>   1. it should be of the form M0.M1...Mn (i.e. without functor applications);
>   2. inside the body of a functor, M0 should not be one of the functor parameters;
>   3. inside a recursive module definition, M0 should not be one of the recursively defined modules.
> 
> Obviously in doing this inside a functor, I violated rule #2.

Indeed

>  What I don't understand is if there are clear syntactic rules, should there not be at least a warning when the rules are violated?

The problem is that module aliases were only introduced recently, and reuse the syntax for module definitions.
While “module M = Arg” in a module is not typed as a module alias, it is still a module definition, and as such there is no reason to warn. (But you have a point that at least optionally warning about this could be a good idea.)
Another reason is that originally module aliases were introduced as an optimization to allow referring to other compilation units without including their whole type in the cmi. This is used in 4.07 to provide a Stdlib module, which contains just pointers to the modules of the standard library. From that point of view, it seemed reasonable to keep the same syntax.

>  Second, how does your solution not still violate rule #1?

Because it doesn’t use a module alias, but a destructive substitution.
A destructive substitution substitutes a module path for a path in the signature, removing this path.
Since it removes it, it doesn’t create an alias, and there is no need for restricting the form of the substituted path.
There are other restrictions on where this path is allowed to appear, and some signatures just cannot be inhabited, though.

Jacques Garrigue

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

      reply	other threads:[~2018-09-21  5:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 14:29 Arlen Cox
2018-09-20 16:02 ` Arlen Cox
2018-09-21  0:10 ` Jacques Garrigue
2018-09-21  1:25   ` Arlen Cox
2018-09-21  5:54     ` Jacques Garrigue [this message]

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=1D5C88F1-E691-4124-BBC6-5DB71E00A716@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=arlencox@gmail.com \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).