Functors #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This module provides additional lemmas, definitions, and instances for functors.
Main definitions #
const αis the functor that sends all types toα.add_const αisconst αbut for whenαhas an additive structure.comp F Gfor functorsFandGis the functor composition ofFandG.liftpandliftrrespectively lift predicates and relations on a typeαtoF α. Terms ofF αare considered to, in some sense, contain values of typeα.
Tags #
functor, applicative
const α is the constant functor, mapping every type to α. When
α has a monoid structure, const α has an applicative instance.
(If α has an additive monoid structure, see functor.add_const.)
Equations
- functor.const α β = α
const.mk is the canonical map α → const α β (the identity), and
it can be used as a pattern to extract this value.
Equations
- functor.const.mk x = x
const.mk' is const.mk but specialized to map α to
const α punit, where punit is the terminal object in Type*.
Equations
- functor.const.mk' x = x
Extract the element of α from the const functor.
The map operation of the const γ functor.
Equations
- functor.const.map f x = x
Equations
- functor.const.functor = {map := functor.const.map γ, map_const := λ (α β : Type u_2), functor.const.map ∘ function.const β}
Equations
- functor.const.inhabited = {default := inhabited.default _inst_1}
add_const α is a synonym for constant functor const α, mapping
every type to α. When α has a additive monoid structure,
add_const α has an applicative instance. (If α has a
multiplicative monoid structure, see functor.const.)
Equations
add_const.mk is the canonical map α → add_const α β, which is the identity,
where add_const α β = const α β. It can be used as a pattern to extract this value.
Equations
Extract the element of α from the constant functor.
Equations
Equations
Equations
- functor.add_const.inhabited = {default := inhabited.default _inst_1}
functor.comp is a wrapper around function.comp for types.
It prevents Lean's type class resolution mechanism from trying
a functor (comp F id) when functor F would do.
Equations
- functor.comp F G α = F (G α)
Construct a term of comp F G α from a term of F (G α), which is the same type.
Can be used as a pattern to extract a term of F (G α).
Equations
- functor.comp.mk x = x
Equations
- functor.comp.inhabited = {default := inhabited.default _inst_1}
The map operation for the composition comp F G of functors F and G.
Equations
- functor.comp.map h (functor.comp.mk x) = functor.comp.mk (functor.map h <$> x)
Equations
- functor.comp.functor = {map := functor.comp.map _inst_2, map_const := λ (α β : Type v), functor.comp.map ∘ function.const β}
The <*> operation for the composition of applicative functors.
Equations
- (functor.comp.mk f).seq (functor.comp.mk x) = functor.comp.mk (has_seq.seq <$> f <*> x)
Equations
- functor.comp.has_pure = {pure := λ (_x : Type v) (x : _x), functor.comp.mk (has_pure.pure (has_pure.pure x))}
Equations
- functor.comp.has_seq = {seq := λ (_x _x_1 : Type v) (f : functor.comp F G (_x → _x_1)) (x : functor.comp F G _x), f.seq x}
Equations
If we consider x : F α to, in some sense, contain values of type α,
predicate liftp p x holds iff every value contained by x satisfies p.
Equations
- functor.liftp p x = ∃ (u : F (subtype p)), subtype.val <$> u = x
If we consider x : F α to, in some sense, contain values of type α, then
liftr r x y relates x and y iff (1) x and y have the same shape and
(2) we can pair values a from x and b from y so that r a b holds.
If we consider x : F α to, in some sense, contain values of type α, then
supp x is the set of values of type α that x contains.
Equations
- functor.supp x = {y : α | ∀ ⦃p : α → Prop⦄, functor.liftp p x → p y}