caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: Mailing List OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] An inconsistency (possibly) in typing constraints with GADT
Date: Wed, 30 Aug 2017 17:29:05 +0900	[thread overview]
Message-ID: <F08103E8-98B2-4A8B-9A73-FAF8A0DF4541@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CALdWJ+z+BKTAtmayiQVqOaF1V-g4GBkR=J8GE_GknvHiSwTSrA@mail.gmail.com>

Sorry for the slow answer,


On 2017/07/14 10:00, Ivan Gotovchits wrote:
> 
> Hi Everyone, 
> 
> I'm wondering, is the following type definition rejected because there is some fundamental reason, that I'm missing, or this is just a missed case in the type checker?
> 
>     type ('a,'b) domain = Domain
>     type 'd exp = Ret : 'a -> 'd exp constraint 'd = ('a,'b) domain
> 
> Fails with:
> 
>      Error: Constraints are not satisfied in this type.
>        Type 'd exp should be an instance of ('a, 'b) domain exp

The problem is the scope of ‘d in the definition of exp above.
It is actually equivalent to
   type ‘d exp = Ret : ‘a -> ‘e exp constraint ‘d = (‘a,’ b) domain

I.e. type variables in GADT clauses use a completely different scope, which ignores constraint clauses.
This makes combining GADTs and constraint very awkward.
On the other hand, a different semantics would be cumbersome too.

Jacques Garrigue

> If we will express the same without GADT, it will be accepted, e.g.,
> 
>     type 'd exp = Ret of 'a constraint 'd = ('a,'b) domain
> 
> 
> And, of course, we can make typechecker happy with
> 
>    type 'd exp = Ret : 'a -> ('a,'b) domain exp constraint 'd = ('a,'b) domain
> 
> However, it will, somewhat, defeat the whole purpose of introducing the constraint, as I'm using constraints as a sort of type abstraction to bind type variables, and to my understanding the [constraint 'x = <type-expression>] makes any occurrence of `'x` to be equivalent to the <type-expression> in its scope. 
> 
> Thanks,
> Ivan
> 
> P.S. Of course, the provided example is a simplification of a real code, where the constraint is really needed. 



      reply	other threads:[~2017-08-30  8:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14  1:00 Ivan Gotovchits
2017-08-30  8:29 ` 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=F08103E8-98B2-4A8B-9A73-FAF8A0DF4541@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=ivg@ieee.org \
    /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).