caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Philippe Veber <philippe.veber@gmail.com>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Narrowing a signature with a constrained type
Date: Sat, 27 Jul 2013 08:35:59 +0900	[thread overview]
Message-ID: <059C2901-8AFE-4E28-B1D2-BC1D660CCA3A@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAOOOohToApXavb6iD01xR==MwCcVg=NZa4w_0qo69KwLdSkiNg@mail.gmail.com>

On 2013/07/26, at 22:32, Philippe Veber <philippe.veber@gmail.com> wrote:

> Dear camlers,
> 
> Out of curiosity, I'd be happy to understand why the following definition is rejected:
> 
> # module type T = sig type 'a format end;;
> module type T = sig type 'a format end
> # module F(X : T with type 'a format = 'a list constraint 'a = < .. >) = struct end;;
> File "", line 1, characters 13-67:                                                                                           Error: In this `with' constraint, the new definition of format does not match its original definition in the constrained signature:                                  
> Type declarations do not match: type 'a format = 'a0 list is not included in type 'a format                                                            
>        Their constraints differ.
> 
> Would it be unsound to allow it?

Well, to ensure the coherence of the with constraints, we require that
the new signature be a subtype of the original one (as a module, not as an object).
This is where your code gets rejected.

Now why is it deemed unsafe to allow a constrained type definition to be a subtype of 
an unconstrained one?
Actually, I don't know.
The unconstrained type does not enforce the invariants of the constrained one,
but they will be checked as soon as you try to unify the two.
So it may be possible to lift this restriction.

However, there are technical difficulties in comparing a constrained definition
with an unconstrained one, so this might just be the main reason.
This would also have an impact on the invariants of types through abstraction.

Jacques

  reply	other threads:[~2013-07-26 23:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-26 13:32 Philippe Veber
2013-07-26 23:35 ` Jacques Garrigue [this message]
2013-07-27 20:07   ` Philippe Veber
2013-07-29  8:51   ` Arnaud Spiwack

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=059C2901-8AFE-4E28-B1D2-BC1D660CCA3A@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=philippe.veber@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;
as well as URLs for NNTP newsgroup(s).