Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Custom record build function

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Custom record build function


Chronological Thread 
  • From: Guillaume Allais <guillaume.allais AT ens-lyon.org>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Custom record build function
  • Date: Wed, 22 Nov 2017 13:31:35 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=guillaume.allais AT ens-lyon.org; spf=None smtp.mailfrom=SRS0=yfwE=CU=ens-lyon.org=guillaume.allais AT bounce.ens-lyon.org; spf=Pass smtp.helo=postmaster AT sonata.ens-lyon.org
  • Ironport-phdr: 9a23:8KCzWxR5WZO4RyxM15RUVZt83dpsv+yvbD5Q0YIujvd0So/mwa67Yh2N2/xhgRfzUJnB7Loc0qyN7PCmBDRIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnZBUin4YAFyP6H+HpPYp8WxzeG7vZPJMCtSgz/oTq5zKBG/sADc/uAShYJjMe5lxQbIpn9BZuFbg2psIVuShD7x4Nz1+I9k9WJXof13pJ0IarnzY6ltFe8QNz8hKW1gvMA=

Hi Joachim,

One way of achieving this is to define a record for `Pair`'s
arguments and to declare `Pair` as an implicit coercion from
that record type to the `OptPair` type. In other words:

============================================================
Record OptPairRecord a b := { fst : a; snd : b }.

Inductive OptPair a b :=
  | Pair : OptPairRecord a b -> OptPair a b
  | NoPair.

Coercion Pair : OptPairRecord >-> OptPair.

Definition c : OptPair nat nat := {| fst := 5; snd := 3 |}.
============================================================

Cheers,
--
gallais

On 21/11/17 18:22, Joachim Breitner wrote:
> Dear all,
>
>
> if I read the reference manual correctly, then
>
> Definition b := {| x := 5; y := 3 |}.
>
> is just syntactic sugar for
>
> Definition b := Build_point 5 3.
>
> This makes me wonder: Can I register, for a type t that is not defined
> using Record, a “build” function and “field names” so that the user can
> use record syntax?
>
> For example given
>
> Inductive OptPair a b := pair a b | no_pair.
>
> can I somehow make
>
> Definition c := {| fst := 5; snd := 3 |}.
>
> accepted notation for
>
> Definition c := pair 5 3
>
>
> Thanks,
> Joachim
>
> BTW, the next question will be if that desugaring then works with the
>
> Instance ... := { … }.
>
> notation.
>
>




Archive powered by MHonArc 2.6.18.

Top of Page