distributors-0.6.0.0: Unifying Parsers, Printers & Grammars
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.Monoidal

Description

 
Synopsis

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 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)))
oneP >*< p = lunit p
p >*< oneP = runit p
p >*< q >*< r = assoc ((p >*< q) >*< r)
dimap (f >*< g) (h >*< i) (p >*< q) = dimap f h p >*< dimap g i q

oneP :: Monoidal p => p () () Source #

oneP is the unit of a Monoidal Profunctor.

(>*<) :: Monoidal p => p a b -> p c d -> p (a, c) (b, d) infixr 5 Source #

>*< is the product of a Monoidal Profunctor.

(>*) :: Monoidal p => p () c -> p a b -> p a b infixl 6 Source #

>* sequences actions, discarding the value of the first argument; analagous to *>, extending it to Monoidal.

oneP >* p = p

(*<) :: Monoidal p => p a b -> p () c -> p a b infixl 6 Source #

*< sequences actions, discarding the value of the second argument; analagous to <*, extending it to Monoidal.

p *< oneP = p

dimap2 Source #

Arguments

:: Monoidal p 
=> (s -> a)

first projection, e.g. fst

-> (s -> c)

second projection, e.g. snd

-> (b -> d -> t)

pairing function, e.g. (,)

-> p a b 
-> p c d 
-> p s t 

dimap2 is a curried, functionalized form of >*<, analagous to liftA2.

foreverP :: Monoidal p => p () c -> p a b Source #

foreverP repeats an action a countable infinity of times; analagous to forever, extending it to Monoidal.

ditraverse :: (Traversable t, Distributive t, Monoidal p) => p a b -> p (t a) (t b) Source #

Thanks to Fy on Monoidal Café Discord.

A Traversable & Distributive type is a homogeneous countable product. That means it is a static countable-length container, so unlike replicateP, ditraverse doesn't need an additional argument for number of repetitions.

Monoidal & Choice

pureP Source #

Arguments

:: (Monoidal p, Choice p) 
=> APrism a b () ()

bidirectional element

-> p a b 

Lift a single bidirectional element into a Monoidal & Choice structure. Bidirectionality is encoded by APrism. Singularity is encoded by the unit type (). Bidirectional elements can be generated from nilary constructors of algebraic datatypes using makeNestedPrisms, from terms of a type with an Eq instance using only, from nil elements using _Empty, or from any .-composition of Prisms terminating with a bidirectional element.

asEmpty :: (AsEmpty s, Monoidal p, Choice p) => p s s Source #

A Monoidal & Choice nil combinator.

(>:<) :: (Cons s t a b, Monoidal p, Choice p) => p a b -> p s t -> p s t infixr 5 Source #

A Monoidal & Choice cons combinator.

replicateP Source #

Arguments

:: (Monoidal p, Choice p, AsEmpty s, Cons s s a a) 
=> Int

number of repetitions

-> p a a 
-> p s s 

replicateP is analagous to replicateM, for Monoidal & Choice Profunctors. When the number of repetitions is less than or equal to 0, it returns asEmpty.

onlyOne :: (Monoidal p, Choice p, IsList s) => p (Item s) (Item s) -> p s s Source #

Use when IsList with onlyOne Item.

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

eotFunList :: forall a1 b1 t1 a2 b2 t2 p f. (Profunctor p, Functor f) => p (Either t1 (a1, Bazaar (->) a1 b1 (b1 -> t1))) (f (Either t2 (a2, Bazaar (->) a2 b2 (b2 -> t2)))) -> p (Bazaar (->) a1 b1 t1) (f (Bazaar (->) a2 b2 t2)) Source #

eotFunList is used to define meander. See van Laarhoven, A non-regular data type challenge, both post and comments, for details.