Distributive Laws¶
A distributive law swaps two layers of monadic
or comonadic structure compatibly with both units and multiplications (Beck, 1969). Moving
from a list of optional values to an optional list, for instance, requires deciding how a missing
element affects the whole result (distributive laws).
The module gives the abstract DistributiveLaw interface.
distributive_laws
¶
Distributive laws for composing monads.
A distributive law λ: S ∘ T ⇒ T ∘ S between monads S and T allows their composition T ∘ S to form a new monad. The component λ_A: S(T(A)) → T(S(A)) "pushes S past T."
This module provides the abstract DistributiveLaw interface.
DistributiveLaw
¶
Bases: ABC
Abstract distributive law λ: S ∘ T ⇒ T ∘ S.
Subclasses must implement outer_monad, inner_monad, and distribute.
outer_monad
abstractmethod
property
¶
outer_monad: Monad
The outer monad S (applied second in S ∘ T).
inner_monad
abstractmethod
property
¶
inner_monad: Monad
The inner monad T (applied first in S ∘ T).
Cited sources¶
Jon Beck. Distributive Laws. In Seminar on Triples and Categorical Homology Theory, Lecture Notes in Mathematics, pages 119–140. Springer, 1969. doi:10.1007/BFb0083084.