| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Profunctor.Distributor
Contents
Description
Synopsis
- class Monoidal p => Distributor (p :: Type -> Type -> Type) where
- dialt :: Distributor p => (s -> Either a c) -> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t
- class (Choice p, Distributor p, forall x. Alternative (p x)) => Alternator (p :: Type -> Type -> Type) where
- choice :: (Foldable f, Alternative p) => f (p a) -> p a
Distributor
class Monoidal p => Distributor (p :: Type -> Type -> Type) where Source #
A Distributor, or lax distributive profunctor,
respects distributive category
structure, that is nilary and binary products and coproducts,
(), (,), Void and Either. It has zero zeroP
and sum >+< lax monoidal structure morphisms.
In addition to the product laws for Monoidal, we have
sum laws for Distributor.
Laws:
>>>let lunit = dimap (either absurd id) Right>>>let runit = dimap (either id absurd) Left>>>:{let assoc = dimap (either (Left . Left) (either (Left . Right) Right)) (either (either Left (Right . Left)) (Right . Right)) :}
zeroP >+< p = lunit p
p >+< zeroP = runit p
p >+< q >+< r = assoc ((p >+< q) >+< r)
dimap (f >+< g) (h >+< i) (p >+< q) = dimap f h p >+< dimap g i q
Distributor additionally has methods manyP & optionalP,
distributing an action over [] and Maybe datatypes,
which generalize to homogeneously
distributing an action over
Homogeneous
sum-of-products datatypes.
Minimal complete definition
Nothing
Methods
(>+<) :: p a b -> p c d -> p (Either a c) (Either b d) infixr 3 Source #
The sum structure morphism of a Distributor.
>+< has a default for Alternators.
x >+< y = alternate (Left x) <|> alternate (Right y)
optionalP :: p a b -> p (Maybe a) (Maybe b) Source #
One or none.
manyP :: p a b -> p [a] [b] Source #
Zero or more.
Instances
dialt :: Distributor p => (s -> Either a c) -> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t Source #
Alternator
class (Choice p, Distributor p, forall x. Alternative (p x)) => Alternator (p :: Type -> Type -> Type) where Source #
The Alternator class co-extends Choice and Distributor,
as well as Alternative, adding the alternate method,
which is a lax monoidal structure morphism on sums,
and methods someP & optionP,
with these these laws relating them.
left' = alternate . Left
right' = alternate . Right
zeroP = empty
x >+< y = alternate (Left x) <|> alternate (Right y)
manyP p = optionP _Empty (someP p)
optionalP p = optionP _Nothing (_Just >? p)
someP p = p >:< manyP p
For the case of Functors, the analog of alternate can be defined
without any other constraint, but the case of Profunctors turns
out to be slighly more complex, necessitating Alternator.
>>>:{alternateF :: Functor f => Either (f a) (f b) -> f (Either a b) alternateF = either (fmap Left) (fmap Right) :}
Not all Distributors are Alternators, in particular (->) is
a Distributor but cannot be Alternative,
because there is no general polymorphic function empty :: a -> b,
so (->) isn't an Alternator.
Minimal complete definition
Nothing
Methods
alternate :: Either (p a b) (p c d) -> p (Either a c) (Either b d) Source #
The structure morphism for an Alternator,
alternate has a default for Choice & Cochoice partial distributors.
someP :: p a b -> p [a] [b] Source #
One or more.
Arguments
| :: APrism a b () () | default |
| -> p a b | |
| -> p a b |
One or zero-with-default.
Instances
| KleeneStarAlgebra k => Alternator (Grammor k) Source # | |
| Categorized (Item s) => Alternator (Parsector s) Source # | |
| Alternator p => Alternator (Coyoneda p) Source # | |
| Alternator p => Alternator (Yoneda p) Source # | |
| Alternator (Binocular a b) Source # | |
Defined in Control.Lens.Bifocal | |
| (Alternative m, Monad m) => Alternator (Parsor s m) Source # | |
| Alternative f => Alternator (Printor s f) Source # | |
| (Alternator p, Applicative f) => Alternator (WrappedPafb f p) Source # | |
Defined in Data.Profunctor.Distributor Methods alternate :: Either (WrappedPafb f p a b) (WrappedPafb f p c d) -> WrappedPafb f p (Either a c) (Either b d) Source # someP :: WrappedPafb f p a b -> WrappedPafb f p [a] [b] Source # optionP :: APrism a b () () -> WrappedPafb f p a b -> WrappedPafb f p a b Source # | |
| Alternative f => Alternator (Joker f :: Type -> Type -> Type) Source # | |
choice :: (Foldable f, Alternative p) => f (p a) -> p a Source #
Combines all Alternative choices in the specified list.