fold_cons_type
generates some value of type 'c
by traversing the structure of cons_sym.sym_type
and accumulating some data of type 'a
.
pos
is the position of the inductive command.
ind_pred_map
is defined above.
x_str
is a string used as prefix for generating variable names when deconstructing a product with LibTerm.unbind_name
.
ind_sym
is an inductive type symbol of ind_pred_map
.
cons_sym
is a constructor symbol of ind_sym
.
inj_var
injects traversed bound variables into the type 'var
.
init
is the initial value of type 'a
.
The traversal is made by the function fold : (xs : 'var list) -> (acc :
'a) -> term -> 'c
below. It keeps track of the variables xs
we went through (the last variable comes first) and some accumulator acc
set to init
at the beginning.
During the traversal, there are several possible cases:
1) If the argument is a product of the form Π x:t, u
with t
of the form Π y₁:a₁, …, Π yₙ:aₙ, s ts
and s
mapped to p
in ind_pred_map
, then the result is rec_dom t x' v next
where x' = inj_var (length xs) x
, v
= aux env s p ts x'
, env = y₁:a₁; …; yₙ:aₙ
and next = fold (x'::xs)
acc' u
is the result of the traversal of u
with the list of variables extended with x
and the accumulator acc' = acc_rec_dom acc x' v
.
2) If the type argument is a product Πx:t, u
not of the previous form, then the result is nonrec_dom t x' next
where next = fold (x'::xs) acc'
u
and acc' = acc_nonrec_dom acc x'
.
3) If the type argument is of the form ind_sym ts
, then the result is codom ts xs acc
.
4) Any other case is an error.