| 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.Monoidal
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
- ditraverse :: (Traversable t, Distributive t, Monoidal p) => p a b -> p (t a) (t b)
- pureP :: (Monoidal p, Choice p) => APrism a b () () -> p a b
- asEmpty :: (AsEmpty s, Monoidal p, Choice p) => p s s
- (>:<) :: (Cons s t a b, Monoidal p, Choice p) => p a b -> p s t -> p s t
- snocP :: (Snoc s t a b, Monoidal p, Choice p) => p s t -> p a b -> p s t
- replicateP :: (Monoidal p, Choice p, AsEmpty s, Cons s s a a) => Int -> p a a -> p s s
- onlyOne :: (Monoidal p, Choice p, IsList s) => p (Item s) (Item s) -> p s s
- idP :: (Monoidal p, Strong p) => p a a
- arrP :: (Monoidal p, Strong p) => (a -> b) -> p a b
- fixP :: (Monoidal p, Strong p, Costrong p) => p (a -> a) a
- meander :: (Monoidal p, Choice p, Strong p) => ATraversal s t a b -> p a b -> p s t
- traverseP :: (Traversable f, Monoidal p, Choice p, Strong p) => p a b -> p (f a) (f b)
- foldP :: (Foldable f, Monoidal p, Choice p, Strong p, forall x. Contravariant (p x)) => p a b -> p (f a) (f b)
- newtype Monoidally (p :: Type -> Type -> Type) a b = Monoidally {
- runMonoidally :: p a b
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)))
prop> oneP >*< p = lunit p prop> p >*< oneP = runit p prop> p >*< q >*< r = assoc ((p >*< q) >*< r) prop> dimap (f >*< g) (h >*< i) (p >*< q) = dimap f h p >*< dimap g i q
(>*<) :: Monoidal p => p a b -> p c d -> p (a, c) (b, d) infixr 5 Source #
>*< is the product of a Monoidal Profunctor.
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
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.
Arguments
| :: (Monoidal p, Choice p, AsEmpty s, Cons s s a a) | |
| => Int | number of repetitions |
| -> p a a | |
| -> p s s |
replicateP is analogous to replicateM,
for Monoidal & Choice Profunctors. When the number
of repetitions is less than or equal to 0, it returns asEmpty.
Monoidal & Strong
idP :: (Monoidal p, Strong p) => p a a Source #
The unit map of a Monoidal & Strong Profunctor,
the strength of oneP, which is natural,
& whose product is the strength.
It needn't be an identity; idP = Forget (const mempty).
prop> lmap f idP = rmap f idP prop> first' p = p >*< idP prop> second' p = idP >*< p
arrP :: (Monoidal p, Strong p) => (a -> b) -> p a b Source #
Lift a function into a Monoidal & Strong Profunctor,
like arr.
prop> arrP f = rmap f idP = lmap f idP
Monoidal, Strong & Costrong
Monoidal, Choice & Strong
meander :: (Monoidal p, Choice p, Strong 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 isn't needed for its definition,
but for its invertibility property.
>>>:{traversalP :: (forall p. (Monoidal p, Choice p, Strong p) => p a b -> p s t) -> Traversal s t a b traversalP f = runStar . f . Star :}
prop> traversalP . meander = id prop> meander . traversalP = id
See Pickering, Gibbons & Wu, Profunctor Optics - Modular Data Accessors
traverseP :: (Traversable f, Monoidal p, Choice p, Strong p) => p a b -> p (f a) (f b) Source #
traverseP gives a default implementation for the
traverse'
method of Traversing.
foldP :: (Foldable f, Monoidal p, Choice p, Strong p, forall x. Contravariant (p x)) => p a b -> p (f a) (f b) Source #
foldP gives a contravariant, profunctorial Foldable method.
However, a Profunctor which is also Contravariant in its last argument
is constant over or phantom in its last argument.
prop> foldMap f = getConst . runStar (foldP (Star (Const . f)))
Deriving via Monoidally
newtype Monoidally (p :: Type -> Type -> Type) a b Source #
Monoidally derives instances of a Monoidal Profunctor,
via meander for Traversing,
& via arrP & >*< for Arrow,
given Category.
newtype P a b = P ... deriving (Traversing, Arrow) via Monoidally P
Constructors
| Monoidally | |
Fields
| |