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 #
Distributive: the distribution of a functor over function types.Distributive.PreservesConst: constant families distribute to constant functions.
Main results #
Distributive.preservesConst_id: the identity functor preserves constant families.Distributive.preservesConst_readerT: so does a reader over a functor that does.SetM.mem_run_distribute: the set functor distributes a family to its choice functions.SetM.not_preservesConst: the set functor does not preserve constant families.
References #
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
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
- Distributive.PreservesConst M = ∀ (ι α : Type ?u.2) (m : M α), (distribute fun (x : ι) => m) = Function.const ι <$> m
Instances For
Equations
- Distributive.instId = { distribute := fun {ι α : Type ?u.1} (f : ι → Id α) => f }
A reader over a distributive functor distributes by reading its environment at every index.
Equations
- Distributive.instReaderT = { distribute := fun {ι α : Type ?u.2} (f : ι → ReaderT ρ M α) (r : ρ) => distribute fun (i : ι) => f i r }
The set functor distributes a family of sets to its choice functions.
Equations
- SetM.instDistributive = { distribute := fun {ι α : Type ?u.1} (f : ι → SetM α) => Set.univ.pi f }
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.