The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Control.Bitraversable.Basic

17 declarations. Mathlib docs · Source

Bitraversable type class

Type class for traversing bifunctors.

Simple examples of Bitraversable are Prod and Sum. A more elaborate example is to define an a-list as:

def AList (key val : Type) := List (key × val)

Then we can use f : key → IO key' and g : val → IO val' to manipulate the AList's key and value respectively with bitraverse f g : AList key val → IO (AList key' val').

Main definitions

  • Bitraversable: Bare typeclass to hold the bitraverse function.
  • LawfulBitraversable: Typeclass for the laws of the bitraverse function. Similar to LawfulTraversable.

References

The concepts and laws are taken from https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Bitraversable.html

Tags

traversable bitraversable iterator functor bifunctor applicative

def Bitraversable.ctorIdx E1 #

{t : Type u → Type u → Type u} → Bitraversable t → ℕ

class Bitraversable E3 #

(Type u → Type u → Type u) → Type (u + 1)

Lawless bitraversable bifunctor. This only holds data for the bimap and bitraverse.

instance Bitraversable.toBifunctor E0 #

{t : Type u → Type u → Type u} → [self : Bitraversable t] → Bifunctor t

ctor Bitraversable.mk E0 #

{t : Type u → Type u → Type u} →
  [toBifunctor : Bifunctor t] →
    ({m : Type u → Type u} → [Applicative m] → {α α' β β' : Type u} → (α → m α') → (β → m β') → t α β → m (t α' β')) →
      Bitraversable t

abbrev Bitraversable.bitraverse E3 #

{t : Type u → Type u → Type u} →
  [self : Bitraversable t] →
    {m : Type u → Type u} → [Applicative m] → {α α' β β' : Type u} → (α → m α') → (β → m β') → t α β → m (t α' β')

def bisequence E1 #

{t : Type u_1 → Type u_1 → Type u_1} →
  {m : Type u_1 → Type u_1} → [Bitraversable t] → [Applicative m] → {α β : Type u_1} → t (m α) (m β) → m (t α β)

A bitraversable functor commutes with all applicative functors.

class LawfulBitraversable E3 #

(t : Type u → Type u → Type u) → [Bitraversable t] → Prop

Bifunctor. This typeclass asserts that a lawless bitraversable bifunctor is lawful.

ctor LawfulBitraversable.mk E0 #

∀ {t : Type u → Type u → Type u} [inst : Bitraversable t] [toLawfulBifunctor : LawfulBifunctor t],
  (∀ {α β : Type u} (x : t α β), bitraverse pure pure x = pure x) →
    (∀ {F G : Type u → Type u} [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F]
        [LawfulApplicative G] {α α' β β' γ γ' : Type u} (f : β → F γ) (f' : β' → F γ') (g : α → G β) (g' : α' → G β')
        (x : t α α'),
        bitraverse (Functor.Comp.mk ∘ Functor.map f ∘ g) (Functor.Comp.mk ∘ Functor.map f' ∘ g') x =
          Functor.Comp.mk (bitraverse f f' <$> bitraverse g g' x)) →
      (∀ {α α' β β' : Type u} (f : α → β) (f' : α' → β') (x : t α α'),
          bitraverse (pure ∘ f) (pure ∘ f') x = pure (bimap f f' x)) →
        (∀ {F G : Type u → Type u} [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F]
            [LawfulApplicative G] (η : ApplicativeTransformation F G) {α α' β β' : Type u} (f : α → F β)
            (f' : α' → F β') (x : t α α'),
            (fun {α} ↦ η.app α) (bitraverse f f' x) =
              bitraverse ((fun {α} ↦ η.app α) ∘ f) ((fun {α} ↦ η.app α) ∘ f') x) →
          LawfulBitraversable t

instance LawfulBitraversable.toLawfulBifunctor E0 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t], LawfulBifunctor t

theorem LawfulBitraversable.id_bitraverse E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {α β : Type u} (x : t α β),
  bitraverse pure pure x = pure x

theorem LawfulBitraversable.comp_bitraverse E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {F G : Type u → Type u}
  [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F] [LawfulApplicative G]
  {α α' β β' γ γ' : Type u} (f : β → F γ) (f' : β' → F γ') (g : α → G β) (g' : α' → G β') (x : t α α'),
  bitraverse (Functor.Comp.mk ∘ Functor.map f ∘ g) (Functor.Comp.mk ∘ Functor.map f' ∘ g') x =
    Functor.Comp.mk (bitraverse f f' <$> bitraverse g g' x)

theorem LawfulBitraversable.bitraverse_eq_bimap_id E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {α α' β β' : Type u}
  (f : α → β) (f' : α' → β') (x : t α α'), bitraverse (pure ∘ f) (pure ∘ f') x = pure (bimap f f' x)

theorem LawfulBitraversable.binaturality E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {F G : Type u → Type u}
  [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F] [LawfulApplicative G]
  (η : ApplicativeTransformation F G) {α α' β β' : Type u} (f : α → F β) (f' : α' → F β') (x : t α α'),
  (fun {α} ↦ η.app α) (bitraverse f f' x) = bitraverse ((fun {α} ↦ η.app α) ∘ f) ((fun {α} ↦ η.app α) ∘ f') x

theorem LawfulBitraversable.bitraverse_id_id E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {α β : Type u},
  bitraverse pure pure = pure

theorem LawfulBitraversable.bitraverse_comp E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {F G : Type u → Type u}
  [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F] [LawfulApplicative G]
  {α α' β β' γ γ' : Type u} (f : β → F γ) (f' : β' → F γ') (g : α → G β) (g' : α' → G β'),
  bitraverse (Functor.Comp.mk ∘ Functor.map f ∘ g) (Functor.Comp.mk ∘ Functor.map f' ∘ g') =
    Functor.Comp.mk ∘ Functor.map (bitraverse f f') ∘ bitraverse g g'

theorem LawfulBitraversable.bitraverse_eq_bimap_id' E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {α α' β β' : Type u}
  (f : α → β) (f' : α' → β'), bitraverse (pure ∘ f) (pure ∘ f') = pure ∘ bimap f f'

theorem LawfulBitraversable.binaturality' E1 #

∀ {t : Type u → Type u → Type u} {inst : Bitraversable t} [self : LawfulBitraversable t] {F G : Type u → Type u}
  [inst_1 : Applicative F] [inst_2 : Applicative G] [LawfulApplicative F] [LawfulApplicative G]
  (η : ApplicativeTransformation F G) {α α' β β' : Type u} (f : α → F β) (f' : α' → F β'),
  (fun {α} ↦ η.app α) ∘ bitraverse f f' = bitraverse ((fun {α} ↦ η.app α) ∘ f) ((fun {α} ↦ η.app α) ∘ f')