Currying and uncurrying of n-ary functions #
A function of n arguments can either be written as f a₁ a₂ ⋯ aₙ or f' ![a₁, a₂, ⋯, aₙ].
This file provides the currying and uncurrying operations that convert between the two, as
n-ary generalizations of the binary curry and uncurry.
Main definitions #
Function.OfArity.uncurry: convert ann-ary function to a function fromFin n → α.Function.OfArity.curry: convert a function fromFin n → αto ann-ary function.Function.FromTypes.uncurry: convert anp-ary heterogeneous function to a function from(i : Fin n) → p i.Function.FromTypes.curry: convert a function from(i : Fin n) → p ito ap-ary heterogeneous function.
def Function.FromTypes.uncurry {n : ℕ} {p : Fin n → Type u} {τ : Type u} (f : FromTypes p τ) :
((i : Fin n) → p i) → τ
Uncurry all the arguments of Function.FromTypes p τ to get
a function from a tuple.
Note this can be used on raw functions if used.
Equations
Instances For
Curry all the arguments of Function.FromTypes p τ to get a function from a tuple.
Equations
- Function.FromTypes.curry x✝ = x✝ fun (a : Fin 0) => isEmptyElim a
- Function.FromTypes.curry x✝ = fun (a : Matrix.vecHead x_4) => Function.FromTypes.curry fun (args : (i : Fin n) → Matrix.vecTail x_4 i) => x✝ (Fin.cons a args)
Instances For
Equiv.curry for p-ary heterogeneous functions.
Equations
- Function.FromTypes.curryEquiv p = { toFun := Function.FromTypes.curry, invFun := Function.FromTypes.uncurry, left_inv := ⋯, right_inv := ⋯ }
Instances For
theorem Function.FromTypes.curry_two_eq_curry {p : Fin 2 → Type u} {τ : Type u} (f : ((i : Fin 2) → p i) → τ) :
theorem Function.FromTypes.uncurry_two_eq_uncurry (p : Fin 2 → Type u) (τ : Type u) (f : FromTypes p τ) :
Uncurry all the arguments of Function.OfArity α n to get a function from a tuple.
Note this can be used on raw functions if used.
Equations
Instances For
Curry all the arguments of Function.OfArity α β n to get a function from a tuple.
Equations
Instances For
Equiv.curry for n-ary functions.
Equations
- Function.OfArity.curryEquiv n = Function.FromTypes.curryEquiv fun (a : Fin n) => α
Instances For
@[simp]