Library Coq.Numbers.NaryFunctions
Local Open Scope type_scope.
Require Import List.
Generic dependently-typed operators about n-ary functions
The type of
n-ary function:
nfun A n B is
A -> ... -> A -> B with
n occurences of
A in this type.
Fixpoint nfun A n B :=
match n with
|
O =>
B
|
S n =>
A -> (
nfun A n B)
end.
Notation " A ^^ n --> B " := (
nfun A n B)
(
at level 50,
n at next level) :
type_scope.
napply_cst _ _ a n f iterates n times the application of a
particular constant a to the n-ary function f.
A generic transformation from an n-ary function to another one.
napply_except_last _ _ n f expects n arguments of type A,
applies n-1 of them to f and discard the last one.
napply_then_last _ _ a n f expects n arguments of type A,
applies them to f and then apply a to the result.
napply_discard _ b n expects n arguments, discards then,
and returns b.
A fold function
n-ary products : nprod A n is A*...*A*unit,
with n occurrences of A in this type.
n-ary curryfication / uncurryfication
Earlier functions can also be defined via ncurry/nuncurry.
For instance :
We can also us it to obtain another fold function,
equivalent to the previous one, but with a nicer expansion
(see for instance Int31.iszero).
From nprod to list
From list to nprod
This gives an additional way to write the fold