caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] An inconsistency (possibly) in typing constraints with GADT
@ 2017-07-14  1:00 Ivan Gotovchits
  2017-08-30  8:29 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Ivan Gotovchits @ 2017-07-14  1:00 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]

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

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.

[-- Attachment #2: Type: text/html, Size: 4087 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-30  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-14  1:00 [Caml-list] An inconsistency (possibly) in typing constraints with GADT Ivan Gotovchits
2017-08-30  8:29 ` Jacques Garrigue

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).