coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Adam Chlipala <adamc AT csail.mit.edu>
- To: Casteran Pierre <pierre.casteran AT labri.fr>
- Cc: Coq Club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] problem with hlists
- Date: Thu, 29 Aug 2013 08:04:12 -0400
On 08/29/2013 07:30 AM, Casteran Pierre wrote:
Using cpdt's hlists, I had to define a function
hset (y:B elm): forall (l:list A)(M:member l) , hlist l -> hlist l.
such that (hset y M hl) returns hl with y at the place defined by M.
I got some solution, but in an interactive definition, using inversion twice. Is there a direct solution (as a variation on hget), making
easy to prove for instance that (hget (hset y M hl)) M = y ?
Yes. Here are the missing ingredients:
Definition hhd ls (hl : hlist ls) : match ls return Type with
| nil => unit
| x :: _ => B x
end :=
match hl with
| HNil => tt
| HCons _ _ v _ => v
end.
Definition htl ls (hl : hlist ls) : match ls return Type with
| nil => unit
| _ :: ls' => hlist ls'
end :=
match hl with
| HNil => tt
| HCons _ _ _ hl' => hl'
end.
Fixpoint hset (y : B elm) l (M : member l) : hlist l -> hlist l :=
match M in member l return hlist l -> hlist l with
| HFirst _ => fun hl => HCons y (htl hl)
| HNext _ _ M' => fun hl => HCons (hhd hl) (hset y M' (htl hl))
end.
Goal forall (y:B elm)(l:list A)(M:member l)(hl:hlist l),
(hget (hset y M hl)) M = y.
induction M; simpl; auto.
Qed.
- [Coq-Club] problem with hlists, Casteran Pierre, 08/29/2013
- Re: [Coq-Club] problem with hlists, Adam Chlipala, 08/29/2013
Archive powered by MHonArc 2.6.18.