| 1 |
From Coq Require Import List. |
| 2 |
Require Export Crypto.Util.FixCoqMistakes. |
| 3 |
Local Set Universe Polymorphism. |
| 4 |
Inductive dyn_list := nil | cons {T} (x : T) (xs : dyn_list). |
| 5 |
Declare Scope dyn_list_scope. |
| 6 |
Delimit Scope dyn_list_scope with dyn_list. |
| 7 |
Bind Scope dyn_list_scope with dyn_list. |
| 8 |
Infix "::" := cons : dyn_list_scope. |
| 9 |
Notation "[ ]" := nil (format "[ ]") : dyn_list_scope. |
| 10 |
Notation "[ x ]" := (cons x nil) : dyn_list_scope. |
| 11 |
Notation "[ x ; y ; .. ; z ]" := (cons x (cons y .. (cons z nil) ..)) : dyn_list_scope. |
| 12 |
|
| 13 |
Module DynList. |
| 14 |
Ltac map_gen explicit f ls N C := |
| 15 |
lazymatch ls with |
| 16 |
| nil => N |
| 17 |
| @cons ?T ?x ?xs |
| 18 |
=> let fx := lazymatch explicit with |
| 19 |
| true => f T x |
| 20 |
| false => f x |
| 21 |
end in |
| 22 |
let xs := map_gen explicit f xs N C in |
| 23 |
constr:(C fx xs) |
| 24 |
end. |
| 25 |
Ltac map_gen_dyn explicit f ls := map_gen explicit f ls constr:(nil) uconstr:(@cons _). |
| 26 |
Ltac map f xs := map_gen_dyn false f xs. |
| 27 |
|
| 28 |
Ltac map_gen_homogenous explicit f ls := map_gen explicit f ls uconstr:(Datatypes.nil) uconstr:(@Datatypes.cons _). |
| 29 |
Ltac map_homogenous f xs := map_gen_homogenous false f xs. |
| 30 |
End DynList. |