| 1 |
From Coq Require Import List. |
| 2 |
Require Import Crypto.Util.PrimitiveProd. |
| 3 |
|
| 4 |
Import Primitive.Notations. |
| 5 |
|
| 6 |
Fixpoint hlist {A} (P : A -> Type) (ls : list A) : Type |
| 7 |
:= match ls return Type with |
| 8 |
| nil => unit |
| 9 |
| cons x xs => P x * @hlist A P xs |
| 10 |
end%type. |
| 11 |
Fixpoint split_list {A P} (ls : list (@sigT A P)) : { ls : list A & hlist P ls } |
| 12 |
:= match ls with |
| 13 |
| nil => existT _ nil tt |
| 14 |
| cons x xs => let 'existT ls' hls' := @split_list A P xs in existT _ (cons (projT1 x) ls') (projT2 x, hls') |
| 15 |
end. |
| 16 |
Fixpoint combine_hlist {A P} (ls : list A) : hlist P ls -> list (@sigT A P) |
| 17 |
:= match ls return hlist P ls -> _ with |
| 18 |
| nil => fun _ => nil |
| 19 |
| cons x xs => fun '(Px, Pxs) => existT P x Px :: @combine_hlist A P xs Pxs |
| 20 |
end. |