| 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 | Safe-Inferred |
| Language | Haskell2010 |
Data.Profunctor.Distributor
Description
Synopsis
- class Monoidal p => Distributor p 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 where
- choice :: (Foldable f, Alternative p) => f (p a) -> p a
- option :: Alternative p => a -> p a -> p a
- class Traversable t => Homogeneous t where
- homogeneously :: Distributor p => p a b -> p (t a) (t b)
- data SepBy p = SepBy {
- beginBy :: p
- endBy :: p
- separateBy :: p
- sepBy :: Monoidal p => p () () -> SepBy (p () ())
- noSep :: Monoidal p => SepBy (p () ())
- several :: (IsList s, IsList t, Distributor p) => SepBy (p () ()) -> p (Item s) (Item t) -> p s t
- several1 :: (IsList s, IsList t, Distributor p, Choice p) => SepBy (p () ()) -> p (Item s) (Item t) -> p s t
- chain :: Alternator p => (forall x. x -> Either x x) -> APartialIso a b (a, a) (b, b) -> APrism a b () () -> SepBy (p () ()) -> p a b -> p a b
- chain1 :: (Distributor p, Choice p) => (forall x. x -> Either x x) -> APartialIso a b (a, a) (b, b) -> SepBy (p () ()) -> p a b -> p a b
- intercalateP :: (Monoidal p, Choice p, AsEmpty s, AsEmpty t, Cons s t a b) => Int -> SepBy (p () ()) -> p a b -> p s t
Distributor
class Monoidal p => Distributor p 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
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 Alternator.
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 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.
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.
Minimal complete definition
Nothing
Methods
alternate :: Either (p a b) (p c d) -> p (Either a c) (Either b d) Source #
left' = alternate . Left
right' = alternate . Right
zeroP = empty
x >+< y = alternate (Left x) <|> alternate (Right y)
someP :: p a b -> p [a] [b] Source #
One or more.
Instances
| KleeneStarAlgebra k => Alternator (Grammor k) Source # | |
| Alternator p => Alternator (Coyoneda p) Source # | |
| Alternator p => Alternator (Yoneda p) Source # | |
| Alternator (Binocular a b) Source # | |
| (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 # | |
choice :: (Foldable f, Alternative p) => f (p a) -> p a Source #
Combines all Alternative choices in the specified list.
Arguments
| :: Alternative p | |
| => a | default value |
| -> p a | |
| -> p a |
Perform an Alternative action or return a default value.
Homogeneous
class Traversable t => Homogeneous t where Source #
A class of Homogeneous
countable sums of countable products.
Minimal complete definition
Nothing
Methods
homogeneously :: Distributor p => p a b -> p (t a) (t b) Source #
Sequences actions homogeneously.
homogeneously @Maybe = optionalP
homogeneously @[] = manyP
Any Traversable & Distributive countable product
can be given a default implementation for the homogeneously method.
homogeneously = ditraverse
And any user-defined homogeneous algebraic datatype has
a default instance for Homogeneous, by deriving Generic1.
default homogeneously :: (Generic1 t, Homogeneous (Rep1 t), Distributor p) => p a b -> p (t a) (t b) Source #
Instances
SepBy
Used to sequence multiple times,
separated by a separateBy,
begun by a beginBy,
and ended by an endBy.
Constructors
| SepBy | |
Fields
| |
Instances
| Foldable SepBy Source # | |
Defined in Data.Profunctor.Distributor Methods fold :: Monoid m => SepBy m -> m # foldMap :: Monoid m => (a -> m) -> SepBy a -> m # foldMap' :: Monoid m => (a -> m) -> SepBy a -> m # foldr :: (a -> b -> b) -> b -> SepBy a -> b # foldr' :: (a -> b -> b) -> b -> SepBy a -> b # foldl :: (b -> a -> b) -> b -> SepBy a -> b # foldl' :: (b -> a -> b) -> b -> SepBy a -> b # foldr1 :: (a -> a -> a) -> SepBy a -> a # foldl1 :: (a -> a -> a) -> SepBy a -> a # elem :: Eq a => a -> SepBy a -> Bool # maximum :: Ord a => SepBy a -> a # minimum :: Ord a => SepBy a -> a # | |
| Traversable SepBy Source # | |
| Functor SepBy Source # | |
| Read p => Read (SepBy p) Source # | |
| Show p => Show (SepBy p) Source # | |
| Eq p => Eq (SepBy p) Source # | |
| Ord p => Ord (SepBy p) Source # | |
Defined in Data.Profunctor.Distributor | |
sepBy :: Monoidal p => p () () -> SepBy (p () ()) Source #
A SepBy smart constructor,
setting the separateBy field,
with no beginning or ending delimitors,
except by updating beginBy or endBy fields.
noSep :: Monoidal p => SepBy (p () ()) Source #
A SepBy smart constructor for no separator,
beginning or ending delimiters.
several :: (IsList s, IsList t, Distributor p) => SepBy (p () ()) -> p (Item s) (Item t) -> p s t Source #
several noSep = manyP
several1 :: (IsList s, IsList t, Distributor p, Choice p) => SepBy (p () ()) -> p (Item s) (Item t) -> p s t Source #
several1 noSep p = someP p
Arguments
| :: Alternator p | |
| => (forall x. x -> Either x x) | |
| -> APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> APrism a b () () | nilary constructor pattern |
| -> SepBy (p () ()) | |
| -> p a b | |
| -> p a b |
Use a nilary constructor pattern to sequence zero times, or associate a binary constructor pattern to sequence one or more times.
Arguments
| :: (Distributor p, Choice p) | |
| => (forall x. x -> Either x x) | |
| -> APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> SepBy (p () ()) | |
| -> p a b | |
| -> p a b |
Associate a binary constructor pattern to sequence one or more times.
intercalateP :: (Monoidal p, Choice p, AsEmpty s, AsEmpty t, Cons s t a b) => Int -> SepBy (p () ()) -> p a b -> p s t Source #
intercalateP adds a SepBy to replicateP.