distributors
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Distributor

Description

 
Synopsis

Distributor

class (Monoidal p, CocartesianMonoidal 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, being both Monoidal and CocartesianMonoidal.

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

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

Instances details
(ArrowZero p, ArrowChoice p) => Distributor (WrappedArrow p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: WrappedArrow p a b -> WrappedArrow p (Maybe a) (Maybe b) Source #

manyP :: WrappedArrow p a b -> WrappedArrow p [a] [b] Source #

Monad m => Distributor (Kleisli m) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Kleisli m a b -> Kleisli m (Maybe a) (Maybe b) Source #

manyP :: Kleisli m a b -> Kleisli m [a] [b] Source #

Distributor p => Distributor (Coyoneda p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Coyoneda p a b -> Coyoneda p (Maybe a) (Maybe b) Source #

manyP :: Coyoneda p a b -> Coyoneda p [a] [b] Source #

Distributor p => Distributor (Yoneda p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Yoneda p a b -> Yoneda p (Maybe a) (Maybe b) Source #

manyP :: Yoneda p a b -> Yoneda p [a] [b] Source #

Distributor (Binocular a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

optionalP :: Binocular a b a0 b0 -> Binocular a b (Maybe a0) (Maybe b0) Source #

manyP :: Binocular a b a0 b0 -> Binocular a b [a0] [b0] Source #

Distributor (Spectacle a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

optionalP :: Spectacle a b a0 b0 -> Spectacle a b (Maybe a0) (Maybe b0) Source #

manyP :: Spectacle a b a0 b0 -> Spectacle a b [a0] [b0] Source #

Distributor (Dioptrice a b) Source # 
Instance details

Defined in Control.Lens.Diopter

Methods

optionalP :: Dioptrice a b a0 b0 -> Dioptrice a b (Maybe a0) (Maybe b0) Source #

manyP :: Dioptrice a b a0 b0 -> Dioptrice a b [a0] [b0] Source #

Distributor (Prismatoid a b) Source # 
Instance details

Defined in Control.Lens.Prismoid

Methods

optionalP :: Prismatoid a b a0 b0 -> Prismatoid a b (Maybe a0) (Maybe b0) Source #

manyP :: Prismatoid a b a0 b0 -> Prismatoid a b [a0] [b0] Source #

Distributor (Prismocular a b) Source # 
Instance details

Defined in Control.Lens.Prismoid

Methods

optionalP :: Prismocular a b a0 b0 -> Prismocular a b (Maybe a0) (Maybe b0) Source #

manyP :: Prismocular a b a0 b0 -> Prismocular a b [a0] [b0] Source #

(Distributor p, Applicative f) => Distributor (WrappedPafb f p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: WrappedPafb f p a b -> WrappedPafb f p (Maybe a) (Maybe b) Source #

manyP :: WrappedPafb f p a b -> WrappedPafb f p [a] [b] Source #

Adjunction f u => Distributor (Costar f) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Costar f a b -> Costar f (Maybe a) (Maybe b) Source #

manyP :: Costar f a b -> Costar f [a] [b] Source #

Monoid s => Distributor (Forget s :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Forget s a b -> Forget s (Maybe a) (Maybe b) Source #

manyP :: Forget s a b -> Forget s [a] [b] Source #

Applicative f => Distributor (Star f) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Star f a b -> Star f (Maybe a) (Maybe b) Source #

manyP :: Star f a b -> Star f [a] [b] Source #

Distributor (->) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: (a -> b) -> Maybe a -> Maybe b Source #

manyP :: (a -> b) -> [a] -> [b] Source #

Decidable f => Distributor (Clown f :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Clown f a b -> Clown f (Maybe a) (Maybe b) Source #

manyP :: Clown f a b -> Clown f [a] [b] Source #

Alternative f => Distributor (Joker f :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Joker f a b -> Joker f (Maybe a) (Maybe b) Source #

manyP :: Joker f a b -> Joker f [a] [b] Source #

Monad m => Distributor (Varifocus a b m) Source # 
Instance details

Defined in Control.Lens.Varifocal

Methods

optionalP :: Varifocus a b m a0 b0 -> Varifocus a b m (Maybe a0) (Maybe b0) Source #

manyP :: Varifocus a b m a0 b0 -> Varifocus a b m [a0] [b0] Source #

(Choice p, Monoidal p, Traversable f, Alternative g) => Distributor (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

optionalP :: Zipporah p f g a b -> Zipporah p f g (Maybe a) (Maybe b) Source #

manyP :: Zipporah p f g a b -> Zipporah p f g [a] [b] Source #

(ArrowZero p, ArrowChoice p) => Distributor (WrappedArrow p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: WrappedArrow p a b -> WrappedArrow p (Maybe a) (Maybe b) Source #

manyP :: WrappedArrow p a b -> WrappedArrow p [a] [b] Source #

(Distributor p, Distributor q) => Distributor (Product p q) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Product p q a b -> Product p q (Maybe a) (Maybe b) Source #

manyP :: Product p q a b -> Product p q [a] [b] Source #

(Applicative f, Distributor p) => Distributor (Cayley f p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Cayley f p a b -> Cayley f p (Maybe a) (Maybe b) Source #

manyP :: Cayley f p a b -> Cayley f p [a] [b] Source #

(Distributor p, Distributor q) => Distributor (Procompose p q) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

optionalP :: Procompose p q a b -> Procompose p q (Maybe a) (Maybe b) Source #

manyP :: Procompose p q a b -> Procompose p q [a] [b] Source #

skipManyP :: Distributor p => p a b -> p () () Source #

Zero or more, skipped: sequencing any number of actions forwards, & none backwards, like whitespace that a parser accepts & a printer omits.

prop> skipManyP p = dimap (const []) (const ()) (manyP p)
>>> [r | (r, "") <- readP_to_S (runJoker (skipManyP (Joker (char ' ')) *< Joker (char 'x'))) "   x"]
[()]

skipOptionalP :: Distributor p => p a b -> p () () Source #

Zero or one, skipped: sequencing one action or none forwards, & none backwards, like a trailing separator that a parser accepts & a printer omits.

>>> [r | (r, "") <- readP_to_S (runJoker (Joker (char 'x') *< skipOptionalP (Joker (char ',')))) "x,"]
"x"

Alternator

class (Distributor p, CocartesianChoice p, forall x. Alternative (p x)) => Alternator (p :: Type -> Type -> Type) where Source #

The Alternator class co-extends CocartesianChoice and Distributor, as well as Alternative, adding methods someP & optionP, with these laws relating them.

prop> manyP p = optionP _Empty (someP p)
prop> optionalP p = optionP _Nothing (_Just >? p)
prop> someP p = p >:< manyP p

These mirror the laws of a KleeneStarAlgebra, starK x = optK (plusK x) & plusK x = x <> starK x, unfolding someP on the left. Its unfolding on the right, someP p = snocP (manyP p) p, mirroring plusK x = starK x <> x, isn't a law though, since a greedy or predictive parser's manyP consumes every p, leaving none for the last; only a backtracking one finds it.

Its Alternative structure agrees with its Alternator structure, many & some repeating an input for manyP & someP.

prop> empty = falseP
prop> (<|>) = (>|<)
prop> many = lmap repeat . manyP
prop> some = lmap repeat . someP

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

someP :: p a b -> p [a] [b] Source #

One or more.

optionP Source #

Arguments

:: APrism a b () ()

default

-> p a b 
-> p a b 

One or zero-with-default.

manyTillP :: p a b -> p [a] [b] -> p [a] [b] Source #

Zero or more, then the rest, p* q, trying the rest first, like manyTill of parsec, the least solution of its unfolding.

prop> manyTillP p q = q >|< p >:< manyTillP p q
prop> manyTillP falseP q = q

It mirrors a KleeneStarAlgebra's starK x <> y, so that a static Alternator, which sequences no input, may define it without recursing, as an input-consuming one, like a parser or printer, can't, since only consuming finds where q begins. It recognizes what manyP p does with q = asEmpty, but trying fewer ps first, rather than more.

quantP :: Int -> Maybe Int -> p a b -> p [a] [b] Source #

A Kleene quantifier, between some numbers of times, inclusive, at least a lower bound, & at most an upper bound, if there's one, like a regular expression's {lo,hi}, or {lo,}. It takes the mandatory times first, then, unbounded, someP or manyP, or, bounded, the optional times, trying more first. It never matches where lo > hi, nor where hi is negative, its counts being those n >= 0 within its bounds.

It mirrors a KleeneStarAlgebra's quantK, so that a static Alternator may keep its counts, rather than unfolding them.

prop> quantP 0 Nothing = manyP
prop> quantP 1 Nothing = someP
prop> quantP n (Just n) = replicateP n, for @n >= 0@

Instances

Instances details
Alternator p => Alternator (Coyoneda p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

someP :: Coyoneda p a b -> Coyoneda p [a] [b] Source #

optionP :: APrism a b () () -> Coyoneda p a b -> Coyoneda p a b Source #

manyTillP :: Coyoneda p a b -> Coyoneda p [a] [b] -> Coyoneda p [a] [b] Source #

quantP :: Int -> Maybe Int -> Coyoneda p a b -> Coyoneda p [a] [b] Source #

Alternator p => Alternator (Yoneda p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

someP :: Yoneda p a b -> Yoneda p [a] [b] Source #

optionP :: APrism a b () () -> Yoneda p a b -> Yoneda p a b Source #

manyTillP :: Yoneda p a b -> Yoneda p [a] [b] -> Yoneda p [a] [b] Source #

quantP :: Int -> Maybe Int -> Yoneda p a b -> Yoneda p [a] [b] Source #

Alternator (Binocular a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

someP :: Binocular a b a0 b0 -> Binocular a b [a0] [b0] Source #

optionP :: APrism a0 b0 () () -> Binocular a b a0 b0 -> Binocular a b a0 b0 Source #

manyTillP :: Binocular a b a0 b0 -> Binocular a b [a0] [b0] -> Binocular a b [a0] [b0] Source #

quantP :: Int -> Maybe Int -> Binocular a b a0 b0 -> Binocular a b [a0] [b0] Source #

Alternator (Spectacle a b) Source # 
Instance details

Defined in Control.Lens.Bifocal

Methods

someP :: Spectacle a b a0 b0 -> Spectacle a b [a0] [b0] Source #

optionP :: APrism a0 b0 () () -> Spectacle a b a0 b0 -> Spectacle a b a0 b0 Source #

manyTillP :: Spectacle a b a0 b0 -> Spectacle a b [a0] [b0] -> Spectacle a b [a0] [b0] Source #

quantP :: Int -> Maybe Int -> Spectacle a b a0 b0 -> Spectacle a b [a0] [b0] Source #

Alternator (Prismatoid a b) Source # 
Instance details

Defined in Control.Lens.Prismoid

Methods

someP :: Prismatoid a b a0 b0 -> Prismatoid a b [a0] [b0] Source #

optionP :: APrism a0 b0 () () -> Prismatoid a b a0 b0 -> Prismatoid a b a0 b0 Source #

manyTillP :: Prismatoid a b a0 b0 -> Prismatoid a b [a0] [b0] -> Prismatoid a b [a0] [b0] Source #

quantP :: Int -> Maybe Int -> Prismatoid a b a0 b0 -> Prismatoid a b [a0] [b0] Source #

Alternator (Prismocular a b) Source # 
Instance details

Defined in Control.Lens.Prismoid

Methods

someP :: Prismocular a b a0 b0 -> Prismocular a b [a0] [b0] Source #

optionP :: APrism a0 b0 () () -> Prismocular a b a0 b0 -> Prismocular a b a0 b0 Source #

manyTillP :: Prismocular a b a0 b0 -> Prismocular a b [a0] [b0] -> Prismocular a b [a0] [b0] Source #

quantP :: Int -> Maybe Int -> Prismocular a b a0 b0 -> Prismocular a b [a0] [b0] Source #

(Alternator p, Applicative f) => Alternator (WrappedPafb f p) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

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 #

manyTillP :: WrappedPafb f p a b -> WrappedPafb f p [a] [b] -> WrappedPafb f p [a] [b] Source #

quantP :: Int -> Maybe Int -> WrappedPafb f p a b -> WrappedPafb f p [a] [b] Source #

Alternative f => Alternator (Joker f :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Distributor

Methods

someP :: Joker f a b -> Joker f [a] [b] Source #

optionP :: APrism a b () () -> Joker f a b -> Joker f a b Source #

manyTillP :: Joker f a b -> Joker f [a] [b] -> Joker f [a] [b] Source #

quantP :: Int -> Maybe Int -> Joker f a b -> Joker f [a] [b] Source #

Monad m => Alternator (Varifocus a b m) Source # 
Instance details

Defined in Control.Lens.Varifocal

Methods

someP :: Varifocus a b m a0 b0 -> Varifocus a b m [a0] [b0] Source #

optionP :: APrism a0 b0 () () -> Varifocus a b m a0 b0 -> Varifocus a b m a0 b0 Source #

manyTillP :: Varifocus a b m a0 b0 -> Varifocus a b m [a0] [b0] -> Varifocus a b m [a0] [b0] Source #

quantP :: Int -> Maybe Int -> Varifocus a b m a0 b0 -> Varifocus a b m [a0] [b0] Source #

(Choice p, Monoidal p, Traversable f, Alternative g) => Alternator (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

someP :: Zipporah p f g a b -> Zipporah p f g [a] [b] Source #

optionP :: APrism a b () () -> Zipporah p f g a b -> Zipporah p f g a b Source #

manyTillP :: Zipporah p f g a b -> Zipporah p f g [a] [b] -> Zipporah p f g [a] [b] Source #

quantP :: Int -> Maybe Int -> Zipporah p f g a b -> Zipporah p f g [a] [b] Source #