From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Alain Frisch <alain@frisch.fr>
Cc: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for feedback: A problem with injectivity and GADTs
Date: Wed, 3 Jul 2013 18:13:44 +0200 [thread overview]
Message-ID: <CAPFanBFU_M+=q4Jk5BaaAhD86KN-E3rdwO6JwdDTRGgcsU-utw@mail.gmail.com> (raw)
In-Reply-To: <51D44C85.3040308@frisch.fr>
> In some cases (in particular to add annotations to make sense of error
> messages), it would be useful to be able to name the type constructor
> introduced by opening the GADT to match the existential type. (I'd put this
> rather high on my wish list around GADTs!)
Indeed, virtually anyone that used GADTs in OCaml encountered that
problem and has a way to name existential type high on his/her
wishlist. We discussed a few ideas in the following bugtracking
dicussion:
http://caml.inria.fr/mantis/view.php?id=5780
On Wed, Jul 3, 2013 at 6:08 PM, Alain Frisch <alain@frisch.fr> wrote:
> On 07/02/2013 01:20 AM, Jacques Garrigue wrote:
>>
>> On 2013/07/01, at 23:47, Alain Frisch <alain@frisch.fr> wrote:
>>
>>> A GADT was recently introduced to replace this with a more direct
>>> representation:
>>>
>>> module ABSTRACT_1_MATCHER (T : sig type 'a t val t: unit t ttype end) :
>>> sig
>>> type _ is_t = Is: 'a ttype -> 'a T.t is_t
>>> val check: 'a ttype -> 'a is_t option
>>> end
>>>
>>> The problem is that this doesn't work any more (because T.t is not
>>> injective).
>>>
>>> For now, I think I'll use:
>>>
>>> module ABSTRACT_1_MATCHER (T : sig type 'a t val t: unit t ttype end) :
>>> sig
>>> type _ is_t = Is: 'b ttype * ('a, 'b T.t) TypEq.t -> 'a is_t
>>> val check : 'a ttype -> 'a is_t option
>>> end
>>>
>>> which is accepted and roughly equivalent (by opening the equality
>>> witness, one can retrieve the static equality 'a == 'b T.t).
>>
>>
>> Nice natural example, and nice workaround.
>
>
> Btw, this is also an example where type-based disambiguation in presence of
> a GADT would be useful. For instance, we currently need to write:
>
> match StringMap_matcher.check t with
> | Some (StringMap_matcher.Is (s, TypEq.Eq)) -> vmap (StringMap.map
> (of_value ~t:s env) x)
> | None -> ...
>
> while one could write:
>
> match StringMap_matcher.check t with
> | Some (Is (s, Eq)) -> vmap (StringMap.map (of_value ~t:s env) x)
> | None -> ...
>
> (see http://caml.inria.fr/mantis/view.php?id=6023 )
>
>
>> Of course, this is not strictly equivalent.
>> For instance suppose the following function:
>> let f (type a) (tt : a T.t ttype) =
>> match check tt with None -> assert false
>> | Some (Is (tta, Eq)) -> (tta : a ttype)
>> The pattern matching will succeed, but tta will only have type "a ttype"
>> if T.t is injective. The nice part is that this is delayed to the use
>> site,
>> where we may have more information about T.t, so this trick may still
>> be useful after introducing injectivity annotations.
>>
>> Anyway, I suppose that this will work fine for you: check is intended
>> to be called on unknown types, so the missing equality should not
>> be a problem.
>
>
> Indeed!
>
> In some cases (in particular to add annotations to make sense of error
> messages), it would be useful to be able to name the type constructor
> introduced by opening the GADT to match the existential type. (I'd put this
> rather high on my wish list around GADTs!)
>
>
> Alain
>
>
> --
> 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
next prev parent reply other threads:[~2013-07-03 16:14 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-28 0:02 Jacques Garrigue
2013-04-28 2:45 ` Markus Mottl
2013-04-28 10:28 ` Jacques Garrigue
2013-04-28 5:54 ` Jacques Le Normand
2013-04-29 3:45 ` Ivan Gotovchits
2013-04-29 4:03 ` Ivan Gotovchits
2013-04-29 5:17 ` Jacques Le Normand
2013-04-29 7:58 ` Alain Frisch
2013-04-29 10:52 ` Jacques Garrigue
2013-04-29 11:23 ` Alain Frisch
2013-04-29 16:37 ` Nathan Mishra Linger
2013-04-29 23:53 ` Jacques Garrigue
2013-04-30 5:45 ` Jacques Garrigue
2013-05-04 6:46 ` Jacques Garrigue
2013-05-04 7:09 ` Gabriel Scherer
2013-05-04 12:28 ` Jacques Garrigue
2013-04-30 6:59 ` Alain Frisch
2013-04-30 7:56 ` Jacques Garrigue
2013-04-30 8:02 ` Alain Frisch
2013-04-30 8:18 ` Jacques Garrigue
2013-04-30 9:11 ` Gabriel Scherer
2013-04-30 9:55 ` Jacques Garrigue
2013-04-30 10:12 ` Leo White
2013-04-30 11:30 ` Gabriel Scherer
2013-04-30 13:06 ` Leo White
2013-04-29 7:59 ` Gabriel Scherer
2013-07-01 14:47 ` Alain Frisch
2013-07-01 23:20 ` Jacques Garrigue
2013-07-03 16:08 ` Alain Frisch
2013-07-03 16:13 ` Gabriel Scherer [this message]
2013-07-04 6:07 ` [Caml-list] Request for feedback: A problem with injectivity oleg
2013-07-04 7:35 ` Alain Frisch
2013-07-05 10:30 ` oleg
2013-07-05 12:02 ` Alain Frisch
2013-07-04 1:00 ` [Caml-list] Request for feedback: A problem with injectivity and GADTs Jacques Garrigue
2013-07-04 8:14 ` Alain Frisch
2013-07-04 8:52 ` Jacques Garrigue
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='CAPFanBFU_M+=q4Jk5BaaAhD86KN-E3rdwO6JwdDTRGgcsU-utw@mail.gmail.com' \
--to=gabriel.scherer@gmail.com \
--cc=alain@frisch.fr \
--cc=caml-list@inria.fr \
--cc=garrigue@math.nagoya-u.ac.jp \
/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