Documentation

Linglib.Core.Control.Distributive

Distributive functors #

A functor M is distributive when every family of computations indexed by a type ι gives one computation of a family, distribute : (ι → M α) → M (ι → α): the functor distributes over the function type, as an applicative functor distributes over a list in McBride and Paterson's dist. Function types are not traversable, since not every applicative functor distributes over them (McBride and Paterson's example is Option over functions from the integers), so distribution is a property of the functor. The identity functor distributes by doing nothing, the set functor by choosing a value at every index, Set.pi, and a reader over a distributive functor by reading its environment at every index.

A distributive functor preserves constant families when a family that computes the same m at every index distributes to the constant functions of the values of m. The identity does, and a reader over a functor that does. The set functor does not: from a set with two values it distributes the constant family to every function into that set, not only the constant ones.

Main definitions #

Main results #

References #

class Distributive (M : Type u → Type v) :
Type (max (u + 1) v)

A functor distributes over function types when a family of computations indexed by ι gives a computation of families.

  • distribute {ι α : Type u} : (ι → M α) → M (ι → α)

    The computation of the family of values of a family of computations.

Instances
    def Distributive.PreservesConst (M : Type u → Type v) [Functor M] [Distributive M] :

    A distributive functor preserves constant families when the family computing m at every index distributes to the constant functions of the values of m.

    Equations
    Instances For
      @[instance_reducible]
      Equations
      @[simp]
      theorem Distributive.distribute_id {ι α : Type u} (f : ι → Id α) :
      @[instance_reducible]
      instance Distributive.instReaderT {ρ : Type u} {M : Type u → Type v} [Distributive M] :
      Distributive (ReaderT ρ M)

      A reader over a distributive functor distributes by reading its environment at every index.

      Equations
      @[simp]
      theorem Distributive.distribute_readerT {ρ ι α : Type u} {M : Type u → Type v} [Distributive M] (f : ι → ReaderT ρ M α) (r : ρ) :
      distribute f r = distribute fun (i : ι) => f i r
      theorem Distributive.preservesConst_readerT {ρ : Type u} {M : Type u → Type u} [Monad M] [Distributive M] (h : PreservesConst M) :
      PreservesConst (ReaderT ρ M)
      @[instance_reducible]

      The set functor distributes a family of sets to its choice functions.

      Equations
      @[simp]
      theorem SetM.mem_run_distribute {ι α : Type u} {f : ι → SetM α} {g : ι → α} :
      g ∈ (distribute f).run ↔ ∀ (i : ι), g i ∈ (f i).run
      theorem SetM.run_map {α β : Type u} (f : α → β) (m : SetM α) :
      (f <$> m).run = f '' m.run

      The set functor does not preserve constant families: from the set of both truth values it distributes the constant family to every function, the identity among them, not only to the two constant functions.