lean4-htt/doc/examples/NFM2022/nfm2.lean
2022-05-23 18:20:37 -07:00

14 lines
312 B
Text

/- First-class functions -/
def twice (f : Nat → Nat) (a : Nat) :=
f (f a)
#check twice
-- (Nat → Nat) → Nat → Nat
#eval twice (fun x => x + 2) 10
theorem twice_add_2 (a : Nat) : twice (fun x => x + 2) a = a + 4 := rfl
-- `(· + 2)` is syntax sugar for `(fun x => x + 2)`.
#eval twice (· + 2) 10