coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Maximilian Wuttke <mwuttke97 AT posteo.de>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Recursive Notation in Coq
- Date: Tue, 28 Jul 2020 15:51:33 +0200
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mwuttke97 AT posteo.de; spf=Pass smtp.mailfrom=mwuttke97 AT posteo.de; spf=None smtp.helo=postmaster AT mout01.posteo.de
- Ironport-phdr: 9a23:n96tihCyerT3u22qNN+5UyQJP3N1i/DPJgcQr6AfoPdwSPT+r8bcNUDSrc9gkEXOFd2Cra4d1ayI6eu+BSQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTagYL5+NhS7oRveusQXjoZpN7o8xAbOrnZUYepd2HlmJUiUnxby58ew+IBs/iFNsP8/9MBOTLv3cb0gQbNXEDopPWY15Nb2tRbYVguA+mEcUmQNnRVWBQXO8Qz3UY3wsiv+sep9xTWaMMjrRr06RTiu86FmQwLuhSwaNTA27XvXh9RugqJVoByvuh9xzYDab46aNvVxYqzTcMgGRWdCRMtdSzBND42+YoYJEuEPPfxYr474p1YWqhWxHwatBOLqyj9Jgn/23Lc10+I8Gg7GwQwgA84OsHfKo97oM6oSVO60zLTUzTXfbPNZxzPw5YrTfxA5pvGMRq5wftTWyUU1CgzKkEydpIr4NDyayuoDqXKU7/Z8Ve2xkW4nrRl8rzmyysswiofHiIAYx1HL+yt5wIg4JNm1RU57b9OrHpZcqy6XOYV5TM0tX21lvDo3x6AbtJC1ciUG1pQqygLDZvGBboOG7BXjVOOLLjd5gnJoYK6whxa28Uih0u3zTM2030xQoipDjNbMqnYA3AHQ5MifUvZx40Ss1DaV2w3S6OxIO045mKvBJ5MgwrM8jpkevEDZEiPrl0j7jbWaels69uS08ejrf7vrqoOaOoRpkA/xKL4ulda6AekgMggBQWyb+eOk2b3m+k35XalKguErnqXDqJDaIt8bprKnDA9SyIos9giwAy+n0NQeg3YHMEpIdA+EgoXpIV3DIfL1Ae2xjlmtijtmxvDLMqXkAprXL3jDlLnhfax6605Z0AczyN5e549ICrEdI/L8REv8ud7DAx8hNAy02PrnB8t61o8ERG2AHLeVMLnOvl+Q+uIvP+6MaZcJtzb6Mvgp/uLhjXskmVAGZqSpxpsWaHWgHvt8OUmZYHzsgs0AEWgQpAY+Qvbq2xW+VmtYYG/3VKYh7Bk6DpinBMHNXNODmruEiQKyDpxTZ2RHA1bELmr0a4aJE6MJdz+OPsxsw2MsTb+6V4Imkx2j4lypg4F7J/bZr3VL/ano08J4srWKyEMCsAdsBsHY6FmjCmF5mmRRF20z271j+RU70lCYzaV/xfBVR4QKu6F5FzwiPJuZ9NRUTsjoU1uYLM+OU0qrRZOqDGNpF4Nj85o1e094Xu6aoFXG1iuuDaUSkuXSVoQz6b7R2D79KpQkxg==
On 28/07/2020 15:32, Adam Chlipala wrote:
> That's harder to do with the solution where you build a list and call a
> Gallina function, but it only requires standard use of heterogeneous
> list types (e.g., see Chapter 9 of CPDT
> <http://adam.chlipala.net/cpdt/>). Type inference is quite smart enough
> to reconstruct a list of types from a (heterogeneous) list of values of
> those types. And, if working with heterogeneous lists doesn't seem
> worth the trouble, you can use a notation that constructs a tuple and
> passes it off to Ltac, which can do recursive traversal of tuples as
> easily as of various list types.
Using pairs + ltac for this is a good idea! I implemented it below.
I also solved the 'problem' that list notation had to be used inside
`chain ... endchain`. Now we can write `chain 1 <=, 2 <=, 3` (note the
comma). This solution uses a scope in which `<=,` is an infix for pairs.
> red {X Y : Type} : phi X -> phi Y -> Prop where phi : Type -> Type
In the code below, I used a slightly different type of `red`, but you
should be able to adapt the code to your type.
```
(* This is a bit different than asked *)
Axiom phi : Type -> Type.
Axiom red : forall {X : Type}, X -> phi X -> Prop.
Ltac chainToProp' xs :=
lazymatch xs with
| pair ?x (pair ?y ?xs) =>
let z := chainToProp' (pair y xs) in
constr:(red x y /\ z)
| pair ?x ?y => constr:(red x y)
end.
Ltac chainToProp xs :=
let z := chainToProp' xs in
exact z.
Axiom X0 : Type.
Axiom a : X0.
Axiom b : phi X0.
Axiom c : phi (phi X0).
Axiom d : phi (phi (phi X0)).
Declare Scope chain.
Delimit Scope chain with chain_scope.
Notation "x <=, y" := (pair x y) (at level 80, right associativity, only
parsing) : chain.
Notation "'chain' xs 'endchain'" := (ltac:(chainToProp (xs %
chain_scope))) (only parsing).
Check chain a <=, b <=, c <=, d endchain.
(* red a b /\ red b c /\ red c d *)
(* : Prop *)
```
- [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Hugo Herbelin, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Hugo Herbelin, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
Archive powered by MHonArc 2.6.19+.