mathlib documentation

control.functor

Functors #

This module provides additional lemmas, definitions, and instances for functors.

Main definitions #

Tags #

functor, applicative

theorem functor.map_id {F : Type uType v} {α : Type u} [functor F] [is_lawful_functor F] :
theorem functor.map_comp_map {F : Type uType v} {α β γ : Type u} [functor F] [is_lawful_functor F] (f : α → β) (g : β → γ) :
theorem functor.ext {F : Type u_1Type u_2} {F1 F2 : functor F} [is_lawful_functor F] [is_lawful_functor F] (H : ∀ (α β : Type u_1) (f : α → β) (x : F α), f <$> x = f <$> x) :
F1 = F2
def id.mk {α : Sort u} :
α → id α

Introduce the id functor. Incidentally, this is pure for id as a monad and as an applicative functor.

Equations
@[nolint]
def functor.const (α : Type u_1) (β : Type u_2) :
Type u_1

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
Instances for functor.const
def functor.const.mk {α : Type u_1} {β : Type u_2} (x : α) :

const.mk is the canonical map α → const α β (the identity), and it can be used as a pattern to extract this value.

Equations
def functor.const.mk' {α : Type u_1} (x : α) :

const.mk' is const.mk but specialized to map α to const α punit, where punit is the terminal object in Type*.

Equations
def functor.const.run {α : Type u_1} {β : Type u_2} (x : functor.const α β) :
α

Extract the element of α from the const functor.

Equations
@[protected]
theorem functor.const.ext {α : Type u_1} {β : Type u_2} {x y : functor.const α β} (h : x.run = y.run) :
x = y
@[protected, nolint]
def functor.const.map {γ : Type u_1} {α : Type u_2} {β : Type u_3} (f : α → β) (x : functor.const γ β) :

The map operation of the const γ functor.

Equations
@[protected, instance]
def functor.const.functor {γ : Type u_1} :
Equations
@[protected, instance]
@[protected, instance]
def functor.const.inhabited {α : Type u_1} {β : Type u_2} [inhabited α] :
Equations
def functor.add_const (α : Type u_1) (β : Type u_2) :
Type u_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
Instances for functor.add_const
def functor.add_const.mk {α : Type u_1} {β : Type u_2} (x : α) :

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
def functor.add_const.run {α : Type u_1} {β : Type u_2} :
functor.add_const α β → α

Extract the element of α from the constant functor.

Equations
@[protected, instance]
Equations
@[protected, instance]
@[protected, instance]
def functor.add_const.inhabited {α : Type u_1} {β : Type u_2} [inhabited α] :
Equations
def functor.comp (F : Type uType w) (G : Type vType u) (α : Type v) :
Type w

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
Instances for functor.comp
def functor.comp.mk {F : Type uType w} {G : Type vType u} {α : Type v} (x : 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
def functor.comp.run {F : Type uType w} {G : Type vType u} {α : Type v} (x : functor.comp F G α) :
F (G α)

Extract a term of F (G α) from a term of comp F G α, which is the same type.

Equations
@[protected]
theorem functor.comp.ext {F : Type uType w} {G : Type vType u} {α : Type v} {x y : functor.comp F G α} :
x.run = y.runx = y
@[protected, instance]
def functor.comp.inhabited {F : Type uType w} {G : Type vType u} {α : Type v} [inhabited (F (G α))] :
Equations
@[protected]
def functor.comp.map {F : Type uType w} {G : Type vType u} [functor F] [functor G] {α β : Type v} (h : α → β) :
functor.comp F G αfunctor.comp F G β

The map operation for the composition comp F G of functors F and G.

Equations
@[protected, instance]
def functor.comp.functor {F : Type uType w} {G : Type vType u} [functor F] [functor G] :
Equations
theorem functor.comp.map_mk {F : Type uType w} {G : Type vType u} [functor F] [functor G] {α β : Type v} (h : α → β) (x : F (G α)) :
@[protected, simp]
theorem functor.comp.run_map {F : Type uType w} {G : Type vType u} [functor F] [functor G] {α β : Type v} (h : α → β) (x : functor.comp F G α) :
@[protected]
theorem functor.comp.id_map {F : Type uType w} {G : Type vType u} [functor F] [functor G] [is_lawful_functor F] [is_lawful_functor G] {α : Type v} (x : functor.comp F G α) :
@[protected]
theorem functor.comp.comp_map {F : Type uType w} {G : Type vType u} [functor F] [functor G] [is_lawful_functor F] [is_lawful_functor G] {α β γ : Type v} (g' : α → β) (h : β → γ) (x : functor.comp F G α) :
@[protected, instance]
def functor.comp.is_lawful_functor {F : Type uType w} {G : Type vType u} [functor F] [functor G] [is_lawful_functor F] [is_lawful_functor G] :
theorem functor.comp.functor_comp_id {F : Type u_1Type u_2} [AF : functor F] [is_lawful_functor F] :
theorem functor.comp.functor_id_comp {F : Type u_1Type u_2} [AF : functor F] [is_lawful_functor F] :
@[protected]
def functor.comp.seq {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] {α β : Type v} :
functor.comp F G (α → β)functor.comp F G αfunctor.comp F G β

The <*> operation for the composition of applicative functors.

Equations
@[protected, instance]
def functor.comp.has_pure {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] :
Equations
@[protected, instance]
def functor.comp.has_seq {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] :
Equations
@[protected, simp]
theorem functor.comp.run_pure {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] {α : Type v} (x : α) :
@[protected, simp]
theorem functor.comp.run_seq {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] {α β : Type v} (f : functor.comp F G (α → β)) (x : functor.comp F G α) :
@[protected, instance]
def functor.comp.applicative {F : Type uType w} {G : Type vType u} [applicative F] [applicative G] :
Equations
def functor.liftp {F : Type uType u} [functor F] {α : Type u} (p : α → Prop) (x : F α) :
Prop

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
def functor.liftr {F : Type uType u} [functor F] {α : Type u} (r : α → α → Prop) (x y : F α) :
Prop

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.

Equations
def functor.supp {F : Type uType u} [functor F] {α : Type u} (x : F α) :
set α

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
theorem functor.of_mem_supp {F : Type uType u} [functor F] {α : Type u} {x : F α} {p : α → Prop} (h : functor.liftp p x) (y : α) (H : y functor.supp x) :
p y