lean2/hott/init/function.hlean

61 lines
1.6 KiB
Text
Raw Normal View History

2014-12-12 18:19:23 +00:00
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.function
2014-12-12 18:19:23 +00:00
Author: Leonardo de Moura
General operations on functions.
-/
prelude
2014-12-16 20:10:12 +00:00
import init.reserved_notation
2014-12-12 18:19:23 +00:00
namespace function
variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
definition compose [reducible] (f : B → C) (g : A → B) : A → C :=
λx, f (g x)
definition id [reducible] (a : A) : A :=
a
definition on_fun [reducible] (f : B → B → C) (g : A → B) : A → A → C :=
2014-12-12 18:19:23 +00:00
λx y, f (g x) (g y)
definition combine [reducible] (f : A → B → C) (op : C → D → E) (g : A → B → D) : A → B → E :=
2014-12-12 18:19:23 +00:00
λx y, op (f x y) (g x y)
definition const [reducible] (B : Type) (a : A) : B → A :=
2014-12-12 18:19:23 +00:00
λx, a
definition dcompose [reducible] {B : A → Type} {C : Π {x : A}, B x → Type}
2014-12-12 18:19:23 +00:00
(f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
λx, f (g x)
definition flip [reducible] {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
2014-12-12 18:19:23 +00:00
λy x, f x y
definition app [reducible] {B : A → Type} (f : Πx, B x) (x : A) : B x :=
2014-12-12 18:19:23 +00:00
f x
precedence `∘'`:60
precedence `on`:1
precedence `$`:1
variables {f g : A → B}
2014-12-16 20:10:12 +00:00
infixr ∘ := compose
2014-12-12 18:19:23 +00:00
infixr ∘' := dcompose
infixl on := on_fun
infixr $ := app
notation f `-[` op `]-` g := combine f op g
-- Trick for using any binary function as infix operator
notation a `⟨` f `⟩` b := f a b
end function
-- copy reducible annotations to top-level
export [reduce-hints] function