| 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
Contents
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
- 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
- meander :: (Monoidal p, Choice p) => ATraversal s t a b -> p a b -> p s t
- 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))
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
(>*<) :: 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 analagous to replicateM,
for Monoidal & Choice Profunctors. When the number
of repetitions is less than or equal to 0, it returns asEmpty.
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.