| Copyright | (C) 2025 - 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
Description
Synopsis
- type Monoidal (p :: Type -> Type -> Type) = (Profunctor p, forall x. Applicative (p x))
- oneP :: Monoidal p => p () ()
- (>*<) :: Monoidal p => p a b -> p c d -> p (a, c) (b, d)
- (>*) :: Monoidal p => p () c -> p a b -> p a b
- (*<) :: Monoidal p => p a b -> p () c -> p a b
- dimap2 :: Monoidal p => (s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
- foreverP :: Monoidal p => p () c -> p a b
- replicateP :: (Traversable t, Distributive t, Monoidal p) => p a b -> p (t a) (t b)
- meander :: (Monoidal p, Choice p) => ATraversal s t a b -> p a b -> p s t
- (>:<) :: (Monoidal p, Choice p, Cons s t a b) => p a b -> p s t -> p s t
- 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 Traversable t => Homogeneous (t :: Type -> Type) where
- homogeneously :: Distributor p => p a b -> p (t a) (t b)
- class (Choice p, Distributor p, forall x. Alternative (p x)) => Alternator (p :: Type -> Type -> Type) where
- class (Cochoice p, forall x. Filterable (p x)) => Filtrator (p :: Type -> Type -> Type) where
- data SepBy (p :: Type -> Type -> Type) = SepBy {
- beginBy :: p () ()
- endBy :: p () ()
- separateBy :: p () ()
- sepBy :: Monoidal p => p () () -> SepBy p
- noSep :: forall (p :: Type -> Type -> Type). Monoidal p => SepBy p
- zeroOrMore :: Distributor p => SepBy p -> p a b -> p [a] [b]
- oneOrMore :: Alternator p => SepBy p -> p a b -> p [a] [b]
- chainl1 :: (Choice p, Cochoice p, Distributor p) => APartialIso a b (a, a) (b, b) -> SepBy p -> p a b -> p a b
- chainr1 :: (Choice p, Cochoice p, Distributor p) => APartialIso a b (a, a) (b, b) -> SepBy p -> p a b -> p a b
- chainl :: (Alternator p, Filtrator p) => APartialIso a b (a, a) (b, b) -> APartialIso a b () () -> SepBy p -> p a b -> p a b
- chainr :: (Alternator p, Filtrator p) => APartialIso a b (a, a) (b, b) -> APartialIso a b () () -> SepBy p -> p a b -> p a b
- class Tokenized a b (p :: Type -> Type -> Type) | p -> a, p -> b where
- anyToken :: p a b
- satisfy :: (Choice p, Cochoice p, Tokenized c c p) => (c -> Bool) -> p c c
- token :: (Cochoice p, Eq c, Tokenized c c p) => c -> p () ()
- tokens :: (Cochoice p, Monoidal p, Eq c, Tokenized c c p) => [c] -> p () ()
- newtype Printor s (f :: Type -> Type) a b = Printor {
- runPrintor :: a -> f (s -> s)
- newtype Parsor s (f :: Type -> Type) a b = Parsor {
- runParsor :: s -> f (b, s)
Monoidal
type Monoidal (p :: Type -> Type -> Type) = (Profunctor p, forall x. Applicative (p x)) Source #
A lax Monoidal product Profunctor has unit oneP
and product >*< lax monoidal structure morphisms.
This is equivalent to the Profunctor also being Applicative.
Laws:
>>>let (f >< g) (a,c) = (f a, g c)>>>let lunit = dimap (\((),a) -> a) (\a -> ((),a))>>>let runit = dimap (\(a,()) -> a) (\a -> (a,()))>>>let assoc = dimap (\(a,(b,c)) -> ((a,b),c)) (\((a,b),c) -> (a,(b,c)))
dimap (f >< g) (h >< i) (p >*< q) = dimap f h p >*< dimap g i q
oneP >*< p = lunit p
p >*< oneP = runit p
p >*< q >*< r = assoc ((p >*< q) >*< r)
(>*<) :: Monoidal p => p a b -> p c d -> p (a, c) (b, d) infixr 6 Source #
>*< is the product of a Monoidal Profunctor.
replicateP :: (Traversable t, Distributive t, Monoidal p) => p a b -> p (t a) (t b) Source #
Thanks to Fy on Monoidal Café Discord.
replicateP is roughly analagous to replicateM,
repeating an action a number of times.
However, instead of an Int term, it expects
a Traversable & Distributive type. Such a
type is a homogeneous countable product.
meander :: (Monoidal p, Choice p) => ATraversal s t a b -> p a b -> p s t Source #
For any Monoidal, Choice & Strong Profunctor,
meander is invertible and gives a default implementation for the
wander
method of Traversing,
though Strong is not needed for its definition.
See Pickering, Gibbons & Wu, Profunctor Optics - Modular Data Accessors
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 f |+| g = either (Left . f) (Right . g) lunit = dimap (either absurd id) Right runit = dimap (either id absurd) Left assoc = dimap (either (Left . Left) (either (Left . Right) Right)) (either (either Left (Right . Left)) (Right . Right)) :}
dimap (f |+| g) (h |+| i) (p >+< q) = dimap f h p >+< dimap g i q
zeroP >+< p = lunit p
p >+< zeroP = runit p
p >+< q >+< r = assoc ((p >+< q) >+< r)
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 #
class Traversable t => Homogeneous (t :: Type -> Type) 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 = replicateP
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
Alternator/Filtrator
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.
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
| Alternator p => Alternator (Coyoneda p) Source # | |
| Alternator p => Alternator (Yoneda p) Source # | |
| Alternator (Binocular a b) Source # | |
| (Monad f, Alternative f) => Alternator (Parsor s f) Source # | |
| Alternative f => Alternator (Printor s f) Source # | |
| (Alternator p, Alternative 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 # | |
class (Cochoice p, forall x. Filterable (p x)) => Filtrator (p :: Type -> Type -> Type) where Source #
The Filtrator class extends Cochoice,
as well as Filterable, adding the filtrate method,
which is an oplax monoidal structure morphism dual to >+<.
Minimal complete definition
Nothing
Methods
filtrate :: p (Either a c) (Either b d) -> (p a b, p c d) Source #
Instances
| Filtrator p => Filtrator (Coyoneda p) Source # | |
| Filtrator p => Filtrator (Yoneda p) Source # | |
| Filtrator (Binocular a b) Source # | |
| Filtrator (PartialExchange a b) Source # | |
Defined in Data.Profunctor.Distributor Methods filtrate :: PartialExchange a b (Either a0 c) (Either b0 d) -> (PartialExchange a b a0 b0, PartialExchange a b c d) Source # | |
| Filterable f => Filtrator (Parsor s f) Source # | |
| Filtrator (Printor s f) Source # | |
| (Filtrator p, Filterable f) => Filtrator (WrappedPafb f p) Source # | |
Defined in Data.Profunctor.Distributor Methods filtrate :: WrappedPafb f p (Either a c) (Either b d) -> (WrappedPafb f p a b, WrappedPafb f p c d) Source # | |
| Filtrator (Forget r :: Type -> Type -> Type) Source # | |
| (Filterable f, Traversable f) => Filtrator (Star f) Source # | |
SepBy
data SepBy (p :: Type -> Type -> Type) Source #
Used to sequence multiple times,
separated by a separateBy,
begun by a beginBy,
and ended by an endBy.
Constructors
| SepBy | |
Fields
| |
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 :: forall (p :: Type -> Type -> Type). Monoidal p => SepBy p Source #
A SepBy smart constructor for no separator,
beginning or ending delimiters.
zeroOrMore :: Distributor p => SepBy p -> p a b -> p [a] [b] Source #
zeroOrMore noSep = manyP
oneOrMore :: Alternator p => SepBy p -> p a b -> p [a] [b] Source #
oneOrMore noSep = someP
Arguments
| :: (Choice p, Cochoice p, Distributor p) | |
| => APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> SepBy p | |
| -> p a b | |
| -> p a b |
Left associate a binary constructor pattern to sequence one or more times.
Arguments
| :: (Choice p, Cochoice p, Distributor p) | |
| => APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> SepBy p | |
| -> p a b | |
| -> p a b |
Right associate a binary constructor pattern to sequence one or more times.
Arguments
| :: (Alternator p, Filtrator p) | |
| => APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> APartialIso a b () () | nilary constructor pattern |
| -> SepBy p | |
| -> p a b | |
| -> p a b |
Left associate a binary constructor pattern to sequence one or more times, or use a nilary constructor pattern to sequence zero times.
Arguments
| :: (Alternator p, Filtrator p) | |
| => APartialIso a b (a, a) (b, b) | binary constructor pattern |
| -> APartialIso a b () () | nilary constructor pattern |
| -> SepBy p | |
| -> p a b | |
| -> p a b |
Right associate a binary constructor pattern to sequence one or more times, or use a nilary constructor pattern to sequence zero times.
Tokenized
class Tokenized a b (p :: Type -> Type -> Type) | p -> a, p -> b where Source #
Tokenized serves two different purposes.
The anyToken method is used
- by token-stream printer/parsers, to sequence a single token;
- and for concrete optics, as an identity morphism.
In the former case the associated input and output token types
are same. In the latter case, observe that Identical is
a free Tokenized.
Instances
| Tokenized a b (Binocular a b) Source # | |
Defined in Control.Lens.Bifocal | |
| Tokenized a b (Dioptrice a b) Source # | |
Defined in Control.Lens.Diopter | |
| Tokenized a b (Grating a b) Source # | |
Defined in Control.Lens.Grate | |
| Tokenized a b (Monocular a b) Source # | |
Defined in Control.Lens.Monocle | |
| Tokenized a b (PartialExchange a b) Source # | |
Defined in Data.Profunctor.Distributor Methods anyToken :: PartialExchange a b a b Source # | |
| Tokenized a b (Exchange a b) Source # | |
Defined in Data.Profunctor.Distributor | |
| Tokenized a b (Market a b) Source # | |
Defined in Data.Profunctor.Distributor | |
| (Alternative f, Cons s s c c) => Tokenized c c (Parsor s f) Source # | |
Defined in Data.Profunctor.Distributor | |
| (Applicative f, Cons s s c c) => Tokenized c c (Printor s f) Source # | |
Defined in Data.Profunctor.Distributor | |
| Tokenized a b (Identical a b) Source # | |
Defined in Data.Profunctor.Distributor | |
satisfy :: (Choice p, Cochoice p, Tokenized c c p) => (c -> Bool) -> p c c Source #
Sequences a single token that satisfies a predicate.
token :: (Cochoice p, Eq c, Tokenized c c p) => c -> p () () Source #
Sequences a single specified token.
Printor/Parsor
newtype Printor s (f :: Type -> Type) a b Source #
A function from things to containers of
functions of strings to strings.
Printor is a degenerate Profunctor which
is constant in its covariant argument.
Constructors
| Printor | |
Fields
| |
Instances
newtype Parsor s (f :: Type -> Type) a b Source #
A function from strings to containers of
pairs of things and strings.
Parsor is a degenerate Profunctor which
is constant in its contravariant argument.
Instances
Orphan instances
| Arrow p => Profunctor (WrappedArrow p) Source # | |
Methods dimap :: (a -> b) -> (c -> d) -> WrappedArrow p b c -> WrappedArrow p a d # lmap :: (a -> b) -> WrappedArrow p b c -> WrappedArrow p a c # rmap :: (b -> c) -> WrappedArrow p a b -> WrappedArrow p a c # (#.) :: forall a b c q. Coercible c b => q b c -> WrappedArrow p a b -> WrappedArrow p a c # (.#) :: forall a b c q. Coercible b a => WrappedArrow p b c -> q a b -> WrappedArrow p a c # | |
| (Profunctor p, Alternative (p a)) => Alternative (Coyoneda p a) Source # | |
| (Profunctor p, Alternative (p a)) => Alternative (Yoneda p a) Source # | |
| (Profunctor p, Applicative (p a)) => Applicative (Coyoneda p a) Source # | |
Methods pure :: a0 -> Coyoneda p a a0 # (<*>) :: Coyoneda p a (a0 -> b) -> Coyoneda p a a0 -> Coyoneda p a b # liftA2 :: (a0 -> b -> c) -> Coyoneda p a a0 -> Coyoneda p a b -> Coyoneda p a c # (*>) :: Coyoneda p a a0 -> Coyoneda p a b -> Coyoneda p a b # (<*) :: Coyoneda p a a0 -> Coyoneda p a b -> Coyoneda p a a0 # | |
| (Profunctor p, Applicative (p a)) => Applicative (Yoneda p a) Source # | |
| (Closed p, Distributive f) => Closed (WrappedPafb f p) Source # | |
Methods closed :: WrappedPafb f p a b -> WrappedPafb f p (x -> a) (x -> b) # | |
| (Profunctor p, Alternative (p a), Applicative f) => Alternative (WrappedPafb f p a) Source # | |
Methods empty :: WrappedPafb f p a a0 # (<|>) :: WrappedPafb f p a a0 -> WrappedPafb f p a a0 -> WrappedPafb f p a a0 # some :: WrappedPafb f p a a0 -> WrappedPafb f p a [a0] # many :: WrappedPafb f p a a0 -> WrappedPafb f p a [a0] # | |
| (Profunctor p, Applicative (p a), Applicative f) => Applicative (WrappedPafb f p a) Source # | |
Methods pure :: a0 -> WrappedPafb f p a a0 # (<*>) :: WrappedPafb f p a (a0 -> b) -> WrappedPafb f p a a0 -> WrappedPafb f p a b # liftA2 :: (a0 -> b -> c) -> WrappedPafb f p a a0 -> WrappedPafb f p a b -> WrappedPafb f p a c # (*>) :: WrappedPafb f p a a0 -> WrappedPafb f p a b -> WrappedPafb f p a b # (<*) :: WrappedPafb f p a a0 -> WrappedPafb f p a b -> WrappedPafb f p a a0 # | |
| Monoid r => Applicative (Forget r a :: Type -> Type) Source # | |
| Decidable f => Applicative (Clown f a :: Type -> Type) Source # | |
| Applicative f => Applicative (Joker f a) Source # | |
| Arrow p => Applicative (WrappedArrow p a) Source # | |
Methods pure :: a0 -> WrappedArrow p a a0 # (<*>) :: WrappedArrow p a (a0 -> b) -> WrappedArrow p a a0 -> WrappedArrow p a b # liftA2 :: (a0 -> b -> c) -> WrappedArrow p a a0 -> WrappedArrow p a b -> WrappedArrow p a c # (*>) :: WrappedArrow p a a0 -> WrappedArrow p a b -> WrappedArrow p a b # (<*) :: WrappedArrow p a a0 -> WrappedArrow p a b -> WrappedArrow p a a0 # | |
| Arrow p => Functor (WrappedArrow p a) Source # | |
Methods fmap :: (a0 -> b) -> WrappedArrow p a a0 -> WrappedArrow p a b # (<$) :: a0 -> WrappedArrow p a b -> WrappedArrow p a a0 # | |
| (Monoidal p, Monoidal q) => Applicative (Product p q a) Source # | |
Methods pure :: a0 -> Product p q a a0 # (<*>) :: Product p q a (a0 -> b) -> Product p q a a0 -> Product p q a b # liftA2 :: (a0 -> b -> c) -> Product p q a a0 -> Product p q a b -> Product p q a c # (*>) :: Product p q a a0 -> Product p q a b -> Product p q a b # (<*) :: Product p q a a0 -> Product p q a b -> Product p q a a0 # | |
| (Applicative f, Applicative (p a)) => Applicative (Cayley f p a) Source # | |
Methods pure :: a0 -> Cayley f p a a0 # (<*>) :: Cayley f p a (a0 -> b) -> Cayley f p a a0 -> Cayley f p a b # liftA2 :: (a0 -> b -> c) -> Cayley f p a a0 -> Cayley f p a b -> Cayley f p a c # (*>) :: Cayley f p a a0 -> Cayley f p a b -> Cayley f p a b # (<*) :: Cayley f p a a0 -> Cayley f p a b -> Cayley f p a a0 # | |
| (Monoidal p, Applicative (q a)) => Applicative (Procompose p q a) Source # | |
Methods pure :: a0 -> Procompose p q a a0 # (<*>) :: Procompose p q a (a0 -> b) -> Procompose p q a a0 -> Procompose p q a b # liftA2 :: (a0 -> b -> c) -> Procompose p q a a0 -> Procompose p q a b -> Procompose p q a c # (*>) :: Procompose p q a a0 -> Procompose p q a b -> Procompose p q a b # (<*) :: Procompose p q a a0 -> Procompose p q a b -> Procompose p q a a0 # | |
| (Functor f, Functor (p a)) => Functor (Cayley f p a) Source # | |