{-|
Module      : Data.Profunctor.Distributor
Description : distributors
Copyright   : (C) 2026 - Eitan Chatav
License     : BSD-style (see the file LICENSE)
Maintainer  : Eitan Chatav <eitan.chatav@gmail.com>
Stability   : provisional
Portability : non-portable
-}

module Data.Profunctor.Distributor
  ( -- * Distributor
    Distributor (..), dialt
    -- * Alternator
  , Alternator (..)
  , choice
  , option
    -- * Homogeneous
  , Homogeneous (..)
    -- * SepBy
  , SepBy (..)
  , sepBy
  , noSep
  , several
  , several1
  , chain
  , chain1
  , intercalateP
  ) where

import Control.Applicative hiding (WrappedArrow)
import Control.Applicative qualified as Ap (WrappedArrow)
import Control.Arrow
import Control.Lens hiding (chosen)
import Control.Lens.Internal.Profunctor
import Control.Lens.PartialIso
import Data.Bifunctor.Clown
import Data.Bifunctor.Joker
import Data.Bifunctor.Product
import Data.Complex
import Data.Foldable hiding (toList)
import Data.Functor.Adjunction
import Data.Functor.Compose
import Data.Functor.Contravariant.Divisible
import qualified Data.Functor.Product as Functor
import qualified Data.Functor.Sum as Functor
import qualified Data.Monoid as Monoid
import Data.Profunctor hiding (WrappedArrow)
import Data.Profunctor qualified as Pro (WrappedArrow)
import Data.Profunctor.Cayley
import Data.Profunctor.Composition
import Data.Profunctor.Monad
import Data.Profunctor.Monoidal
import Data.Profunctor.Yoneda
import Data.Proxy
import Data.Sequence (Seq)
import Data.Tagged
import Data.Tree (Tree (..))
import Data.Vector (Vector)
import Data.Void
import GHC.Exts
import GHC.Generics

-- Distributor --

{- | A `Distributor`, or lax distributive profunctor,
respects [distributive category]
(https://ncatlab.org/nlab/show/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 lunit = dimap (either absurd id) Right
>>> let runit = dimap (either id absurd) Left
>>> :{
let assoc = dimap
      (either (Left . Left) (either (Left . Right) Right))
      (either (either Left (Right . Left)) (Right . Right))
:}

prop> zeroP >+< p = lunit p
prop> p >+< zeroP = 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

-}
class Monoidal p => Distributor p where

  {- | The zero structure morphism of a `Distributor`.

  `zeroP` has a default for `Alternator`.

  prop> zeroP = empty
  -}
  zeroP :: p Void Void
  default zeroP :: Alternator p => p Void Void
  zeroP = p Void Void
forall a. p Void a
forall (f :: * -> *) a. Alternative f => f a
empty

  {- | The sum structure morphism of a `Distributor`.

  `>+<` has a default for `Alternator`.

  prop> x >+< y = alternate (Left x) <|> alternate (Right y)
  -}
  (>+<) :: p a b -> p c d -> p (Either a c) (Either b d)
  default (>+<)
    :: Alternator p
    => p a b -> p c d -> p (Either a c) (Either b d)
  p a b
x >+< p c d
y = Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p a b -> Either (p a b) (p c d)
forall a b. a -> Either a b
Left p a b
x) p (Either a c) (Either b d)
-> p (Either a c) (Either b d) -> p (Either a c) (Either b d)
forall a. p (Either a c) a -> p (Either a c) a -> p (Either a c) a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p c d -> Either (p a b) (p c d)
forall a b. b -> Either a b
Right p c d
y)
  infixr 3 >+<

  {- | One or none. -}
  optionalP :: p a b -> p (Maybe a) (Maybe b)
  optionalP p a b
p = Exchange
  (Either () a) (Either () b) (Either () a) (Identity (Either () b))
-> Exchange
     (Either () a) (Either () b) (Maybe a) (Identity (Maybe b))
forall a b (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Either () a) (f (Either () b)) -> p (Maybe a) (f (Maybe b))
eotMaybe (Exchange
   (Either () a) (Either () b) (Either () a) (Identity (Either () b))
 -> Exchange
      (Either () a) (Either () b) (Maybe a) (Identity (Maybe b)))
-> p (Either () a) (Either () b) -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () () -> p a b -> p (Either () a) (Either () b)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a b
p

  {- | Zero or more. -}
  manyP :: p a b -> p [a] [b]
  manyP p a b
p = Exchange
  (Either () (a, [a]))
  (Either () (b, [b]))
  (Either () (a, [a]))
  (Identity (Either () (b, [b])))
-> Exchange
     (Either () (a, [a])) (Either () (b, [b])) [a] (Identity [b])
forall s a t b.
(Cons s s a a, AsEmpty t, Cons t t b b) =>
Iso s t (Either () (a, s)) (Either () (b, t))
Iso [a] [b] (Either () (a, [a])) (Either () (b, [b]))
eotList (Exchange
   (Either () (a, [a]))
   (Either () (b, [b]))
   (Either () (a, [a]))
   (Identity (Either () (b, [b])))
 -> Exchange
      (Either () (a, [a])) (Either () (b, [b])) [a] (Identity [b]))
-> p (Either () (a, [a])) (Either () (b, [b])) -> p [a] [b]
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () ()
-> p (a, [a]) (b, [b])
-> p (Either () (a, [a])) (Either () (b, [b]))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a b
p p a b -> p [a] [b] -> p (a, [a]) (b, [b])
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP p a b
p

instance Distributor (->) where
  zeroP :: Void -> Void
zeroP = Void -> Void
forall a. a -> a
id
  >+< :: forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
(>+<) = (a -> b) -> (c -> d) -> Either a c -> Either b d
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (a :: * -> * -> *) b c b' c'.
ArrowChoice a =>
a b c -> a b' c' -> a (Either b b') (Either c c')
(+++)
instance Monoid s => Distributor (Forget s) where
  zeroP :: Forget s Void Void
zeroP = (Void -> s) -> Forget s Void Void
forall {k} r a (b :: k). (a -> r) -> Forget r a b
Forget Void -> s
forall a. Void -> a
absurd
  Forget a -> s
kL >+< :: forall a b c d.
Forget s a b -> Forget s c d -> Forget s (Either a c) (Either b d)
>+< Forget c -> s
kR = (Either a c -> s) -> Forget s (Either a c) (Either b d)
forall {k} r a (b :: k). (a -> r) -> Forget r a b
Forget ((a -> s) -> (c -> s) -> Either a c -> s
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> s
kL c -> s
kR)
instance Decidable f => Distributor (Clown f) where
  zeroP :: Clown f Void Void
zeroP = f Void -> Clown f Void Void
forall {k} {k1} (f :: k -> *) (a :: k) (b :: k1).
f a -> Clown f a b
Clown f Void
forall (f :: * -> *). Decidable f => f Void
lost
  Clown f a
x >+< :: forall a b c d.
Clown f a b -> Clown f c d -> Clown f (Either a c) (Either b d)
>+< Clown f c
y = f (Either a c) -> Clown f (Either a c) (Either b d)
forall {k} {k1} (f :: k -> *) (a :: k) (b :: k1).
f a -> Clown f a b
Clown (f a -> f c -> f (Either a c)
forall (f :: * -> *) b c.
Decidable f =>
f b -> f c -> f (Either b c)
chosen f a
x f c
y)
instance Alternative f => Distributor (Joker f) where
  zeroP :: Joker f Void Void
zeroP = f Void -> Joker f Void Void
forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker f Void
forall a. f a
forall (f :: * -> *) a. Alternative f => f a
empty
  Joker f b
x >+< :: forall a b c d.
Joker f a b -> Joker f c d -> Joker f (Either a c) (Either b d)
>+< Joker f d
y = f (Either b d) -> Joker f (Either a c) (Either b d)
forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker (b -> Either b d
forall a b. a -> Either a b
Left (b -> Either b d) -> f b -> f (Either b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
x f (Either b d) -> f (Either b d) -> f (Either b d)
forall a. f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> d -> Either b d
forall a b. b -> Either a b
Right (d -> Either b d) -> f d -> f (Either b d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f d
y)
  optionalP :: forall a b. Joker f a b -> Joker f (Maybe a) (Maybe b)
optionalP (Joker f b
x) = f (Maybe b) -> Joker f (Maybe a) (Maybe b)
forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker (f b -> f (Maybe b)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional f b
x)
  manyP :: forall a b. Joker f a b -> Joker f [a] [b]
manyP (Joker f b
x) = f [b] -> Joker f [a] [b]
forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker (f b -> f [b]
forall a. f a -> f [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many f b
x)
instance (Distributor p, Applicative f)
  => Distributor (WrappedPafb f p) where
    zeroP :: WrappedPafb f p Void Void
zeroP = p Void (f Void) -> WrappedPafb f p Void Void
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb ((Void -> f Void) -> p Void Void -> p Void (f Void)
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap Void -> f Void
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP)
    WrapPafb p a (f b)
x >+< :: forall a b c d.
WrappedPafb f p a b
-> WrappedPafb f p c d -> WrappedPafb f p (Either a c) (Either b d)
>+< WrapPafb p c (f d)
y = p (Either a c) (f (Either b d))
-> WrappedPafb f p (Either a c) (Either b d)
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb (p (Either a c) (f (Either b d))
 -> WrappedPafb f p (Either a c) (Either b d))
-> p (Either a c) (f (Either b d))
-> WrappedPafb f p (Either a c) (Either b d)
forall a b. (a -> b) -> a -> b
$
      (Either a c -> Either a c)
-> (f b -> f (Either b d))
-> (f d -> f (Either b d))
-> p a (f b)
-> p c (f d)
-> p (Either a c) (f (Either b d))
forall (p :: * -> * -> *) s a c b t d.
Distributor p =>
(s -> Either a c)
-> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t
dialt Either a c -> Either a c
forall a. a -> a
id ((b -> Either b d) -> f b -> f (Either b d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b d
forall a b. a -> Either a b
Left) ((d -> Either b d) -> f d -> f (Either b d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> Either b d
forall a b. b -> Either a b
Right) p a (f b)
x p c (f d)
y
    manyP :: forall a b. WrappedPafb f p a b -> WrappedPafb f p [a] [b]
manyP (WrapPafb p a (f b)
x) = p [a] (f [b]) -> WrappedPafb f p [a] [b]
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb (([f b] -> f [b]) -> p [a] [f b] -> p [a] (f [b])
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap [f b] -> f [b]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA (p a (f b) -> p [a] [f b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP p a (f b)
x))
    optionalP :: forall a b.
WrappedPafb f p a b -> WrappedPafb f p (Maybe a) (Maybe b)
optionalP (WrapPafb p a (f b)
x) = p (Maybe a) (f (Maybe b)) -> WrappedPafb f p (Maybe a) (Maybe b)
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb ((Maybe (f b) -> f (Maybe b))
-> p (Maybe a) (Maybe (f b)) -> p (Maybe a) (f (Maybe b))
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap Maybe (f b) -> f (Maybe b)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => Maybe (f a) -> f (Maybe a)
sequenceA (p a (f b) -> p (Maybe a) (Maybe (f b))
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP p a (f b)
x))
instance Applicative f => Distributor (Star f) where
  zeroP :: Star f Void Void
zeroP = (Void -> f Void) -> Star f Void Void
forall {k} (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star Void -> f Void
forall a. Void -> a
absurd
  Star a -> f b
f >+< :: forall a b c d.
Star f a b -> Star f c d -> Star f (Either a c) (Either b d)
>+< Star c -> f d
g =
    (Either a c -> f (Either b d)) -> Star f (Either a c) (Either b d)
forall {k} (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star ((a -> f (Either b d))
-> (c -> f (Either b d)) -> Either a c -> f (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((b -> Either b d) -> f b -> f (Either b d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either b d
forall a b. a -> Either a b
Left (f b -> f (Either b d)) -> (a -> f b) -> a -> f (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f) ((d -> Either b d) -> f d -> f (Either b d)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap d -> Either b d
forall a b. b -> Either a b
Right (f d -> f (Either b d)) -> (c -> f d) -> c -> f (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> f d
g))
  optionalP :: forall a b. Star f a b -> Star f (Maybe a) (Maybe b)
optionalP (Star a -> f b
f) = (Maybe a -> f (Maybe b)) -> Star f (Maybe a) (Maybe b)
forall {k} (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star ((a -> f b) -> Maybe a -> f (Maybe b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse a -> f b
f)
  manyP :: forall a b. Star f a b -> Star f [a] [b]
manyP (Star a -> f b
f) = ([a] -> f [b]) -> Star f [a] [b]
forall {k} (f :: k -> *) d (c :: k). (d -> f c) -> Star f d c
Star ((a -> f b) -> [a] -> f [b]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse a -> f b
f)
deriving via (Star m) instance Monad m => Distributor (Kleisli m)
instance Adjunction f u => Distributor (Costar f) where
  zeroP :: Costar f Void Void
zeroP = (f Void -> Void) -> Costar f Void Void
forall {k} (f :: k -> *) (d :: k) c. (f d -> c) -> Costar f d c
Costar f Void -> Void
forall (f :: * -> *) (u :: * -> *).
Adjunction f u =>
f Void -> Void
unabsurdL
  Costar f a -> b
f >+< :: forall a b c d.
Costar f a b -> Costar f c d -> Costar f (Either a c) (Either b d)
>+< Costar f c -> d
g = (f (Either a c) -> Either b d)
-> Costar f (Either a c) (Either b d)
forall {k} (f :: k -> *) (d :: k) c. (f d -> c) -> Costar f d c
Costar ((f a -> b) -> (f c -> d) -> Either (f a) (f c) -> Either b d
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap f a -> b
f f c -> d
g (Either (f a) (f c) -> Either b d)
-> (f (Either a c) -> Either (f a) (f c))
-> f (Either a c)
-> Either b d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (Either a c) -> Either (f a) (f c)
forall (f :: * -> *) (u :: * -> *) a b.
Adjunction f u =>
f (Either a b) -> Either (f a) (f b)
cozipL)
instance (Applicative f, Distributor p)
  => Distributor (Cayley f p) where
    zeroP :: Cayley f p Void Void
zeroP = f (p Void Void) -> Cayley f p Void Void
forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley (p Void Void -> f (p Void Void)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP)
    Cayley f (p a b)
x >+< :: forall a b c d.
Cayley f p a b
-> Cayley f p c d -> Cayley f p (Either a c) (Either b d)
>+< Cayley f (p c d)
y = f (p (Either a c) (Either b d))
-> Cayley f p (Either a c) (Either b d)
forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley (p a b -> p c d -> p (Either a c) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
(>+<) (p a b -> p c d -> p (Either a c) (Either b d))
-> f (p a b) -> f (p c d -> p (Either a c) (Either b d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p a b)
x f (p c d -> p (Either a c) (Either b d))
-> f (p c d) -> f (p (Either a c) (Either b d))
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (p c d)
y)
    optionalP :: forall a b. Cayley f p a b -> Cayley f p (Maybe a) (Maybe b)
optionalP (Cayley f (p a b)
x) = f (p (Maybe a) (Maybe b)) -> Cayley f p (Maybe a) (Maybe b)
forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley (p a b -> p (Maybe a) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP (p a b -> p (Maybe a) (Maybe b))
-> f (p a b) -> f (p (Maybe a) (Maybe b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p a b)
x)
    manyP :: forall a b. Cayley f p a b -> Cayley f p [a] [b]
manyP (Cayley f (p a b)
x) = f (p [a] [b]) -> Cayley f p [a] [b]
forall {k} {k1} {k2} (f :: k -> *) (p :: k1 -> k2 -> k) (a :: k1)
       (b :: k2).
f (p a b) -> Cayley f p a b
Cayley (p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b -> p [a] [b]) -> f (p a b) -> f (p [a] [b])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (p a b)
x)
instance (ArrowZero p, ArrowChoice p)
  => Distributor (Pro.WrappedArrow p) where
    zeroP :: WrappedArrow p Void Void
zeroP = WrappedArrow p Void Void
forall b c. WrappedArrow p b c
forall (a :: * -> * -> *) b c. ArrowZero a => a b c
zeroArrow
    >+< :: forall a b c d.
WrappedArrow p a b
-> WrappedArrow p c d -> WrappedArrow p (Either a c) (Either b d)
(>+<) = WrappedArrow p a b
-> WrappedArrow p c d -> WrappedArrow p (Either a c) (Either b d)
forall a b c d.
WrappedArrow p a b
-> WrappedArrow p c d -> WrappedArrow p (Either a c) (Either b d)
forall (a :: * -> * -> *) b c b' c'.
ArrowChoice a =>
a b c -> a b' c' -> a (Either b b') (Either c c')
(+++)
deriving via (Pro.WrappedArrow p)
  instance (ArrowZero p, ArrowChoice p)
    => Distributor (Ap.WrappedArrow p)
instance (Distributor p, Distributor q)
  => Distributor (Procompose p q) where
    zeroP :: Procompose p q Void Void
zeroP = p Void Void -> q Void Void -> Procompose p q Void Void
forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP q Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
    Procompose p x b
xL q a x
yL >+< :: forall a b c d.
Procompose p q a b
-> Procompose p q c d -> Procompose p q (Either a c) (Either b d)
>+< Procompose p x d
xR q c x
yR =
      p (Either x x) (Either b d)
-> q (Either a c) (Either x x)
-> Procompose p q (Either a c) (Either b d)
forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose (p x b
xL p x b -> p x d -> p (Either x x) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p x d
xR) (q a x
yL q a x -> q c x -> q (Either a c) (Either x x)
forall a b c d. q a b -> q c d -> q (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< q c x
yR)
    optionalP :: forall a b.
Procompose p q a b -> Procompose p q (Maybe a) (Maybe b)
optionalP (Procompose p x b
f q a x
g) =
      p (Maybe x) (Maybe b)
-> q (Maybe a) (Maybe x) -> Procompose p q (Maybe a) (Maybe b)
forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose (p x b -> p (Maybe x) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP p x b
f) (q a x -> q (Maybe a) (Maybe x)
forall a b. q a b -> q (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP q a x
g)
    manyP :: forall a b. Procompose p q a b -> Procompose p q [a] [b]
manyP (Procompose p x b
f q a x
g) =
      p [x] [b] -> q [a] [x] -> Procompose p q [a] [b]
forall {k} {k1} {k2} (p :: k -> k1 -> *) (x :: k) (c :: k1)
       (q :: k2 -> k -> *) (d :: k2).
p x c -> q d x -> Procompose p q d c
Procompose (p x b -> p [x] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP p x b
f) (q a x -> q [a] [x]
forall a b. q a b -> q [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP q a x
g)
instance (Distributor p, Distributor q)
  => Distributor (Product p q) where
    zeroP :: Product p q Void Void
zeroP = p Void Void -> q Void Void -> Product p q Void Void
forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Pair p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP q Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
    Pair p a b
x0 q a b
y0 >+< :: forall a b c d.
Product p q a b
-> Product p q c d -> Product p q (Either a c) (Either b d)
>+< Pair p c d
x1 q c d
y1 = p (Either a c) (Either b d)
-> q (Either a c) (Either b d)
-> Product p q (Either a c) (Either b d)
forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Pair (p a b
x0 p a b -> p c d -> p (Either a c) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p c d
x1) (q a b
y0 q a b -> q c d -> q (Either a c) (Either b d)
forall a b c d. q a b -> q c d -> q (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< q c d
y1)
    optionalP :: forall a b. Product p q a b -> Product p q (Maybe a) (Maybe b)
optionalP (Pair p a b
f q a b
g) =
      p (Maybe a) (Maybe b)
-> q (Maybe a) (Maybe b) -> Product p q (Maybe a) (Maybe b)
forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Pair (p a b -> p (Maybe a) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP p a b
f) (q a b -> q (Maybe a) (Maybe b)
forall a b. q a b -> q (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP q a b
g)
    manyP :: forall a b. Product p q a b -> Product p q [a] [b]
manyP (Pair p a b
f q a b
g) =
      p [a] [b] -> q [a] [b] -> Product p q [a] [b]
forall {k} {k1} (f :: k -> k1 -> *) (g :: k -> k1 -> *) (a :: k)
       (b :: k1).
f a b -> g a b -> Product f g a b
Pair (p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP p a b
f) (q a b -> q [a] [b]
forall a b. q a b -> q [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP q a b
g)
instance Distributor p => Distributor (Yoneda p) where
  zeroP :: Yoneda p Void Void
zeroP = p Void Void -> Yoneda p Void Void
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
  Yoneda p a b
ab >+< :: forall a b c d.
Yoneda p a b -> Yoneda p c d -> Yoneda p (Either a c) (Either b d)
>+< Yoneda p c d
cd = p (Either a c) (Either b d) -> Yoneda p (Either a c) (Either b d)
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Yoneda p a b -> p a b
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Yoneda p a b
ab p a b -> p c d -> p (Either a c) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Yoneda p c d -> p c d
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Yoneda p c d
cd)
  optionalP :: forall a b. Yoneda p a b -> Yoneda p (Maybe a) (Maybe b)
optionalP = p (Maybe a) (Maybe b) -> Yoneda p (Maybe a) (Maybe b)
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p (Maybe a) (Maybe b) -> Yoneda p (Maybe a) (Maybe b))
-> (Yoneda p a b -> p (Maybe a) (Maybe b))
-> Yoneda p a b
-> Yoneda p (Maybe a) (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (Maybe a) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP (p a b -> p (Maybe a) (Maybe b))
-> (Yoneda p a b -> p a b) -> Yoneda p a b -> p (Maybe a) (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Yoneda p a b -> p a b
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract
  manyP :: forall a b. Yoneda p a b -> Yoneda p [a] [b]
manyP = p [a] [b] -> Yoneda p [a] [b]
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p [a] [b] -> Yoneda p [a] [b])
-> (Yoneda p a b -> p [a] [b]) -> Yoneda p a b -> Yoneda p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b -> p [a] [b])
-> (Yoneda p a b -> p a b) -> Yoneda p a b -> p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Yoneda p a b -> p a b
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract
instance Distributor p => Distributor (Coyoneda p) where
  zeroP :: Coyoneda p Void Void
zeroP = p Void Void -> Coyoneda p Void Void
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
  Coyoneda p a b
ab >+< :: forall a b c d.
Coyoneda p a b
-> Coyoneda p c d -> Coyoneda p (Either a c) (Either b d)
>+< Coyoneda p c d
cd = p (Either a c) (Either b d) -> Coyoneda p (Either a c) (Either b d)
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Coyoneda p a b -> p a b
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Coyoneda p a b
ab p a b -> p c d -> p (Either a c) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< Coyoneda p c d -> p c d
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Coyoneda p c d
cd)
  optionalP :: forall a b. Coyoneda p a b -> Coyoneda p (Maybe a) (Maybe b)
optionalP = p (Maybe a) (Maybe b) -> Coyoneda p (Maybe a) (Maybe b)
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p (Maybe a) (Maybe b) -> Coyoneda p (Maybe a) (Maybe b))
-> (Coyoneda p a b -> p (Maybe a) (Maybe b))
-> Coyoneda p a b
-> Coyoneda p (Maybe a) (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (Maybe a) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP (p a b -> p (Maybe a) (Maybe b))
-> (Coyoneda p a b -> p a b)
-> Coyoneda p a b
-> p (Maybe a) (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coyoneda p a b -> p a b
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract
  manyP :: forall a b. Coyoneda p a b -> Coyoneda p [a] [b]
manyP = p [a] [b] -> Coyoneda p [a] [b]
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p [a] [b] -> Coyoneda p [a] [b])
-> (Coyoneda p a b -> p [a] [b])
-> Coyoneda p a b
-> Coyoneda p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b -> p [a] [b])
-> (Coyoneda p a b -> p a b) -> Coyoneda p a b -> p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coyoneda p a b -> p a b
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract

{- | `dialt` is a functionalized form of `>+<`. -}
dialt
  :: Distributor p
  => (s -> Either a c)
  -> (b -> t)
  -> (d -> t)
  -> p a b -> p c d -> p s t
dialt :: forall (p :: * -> * -> *) s a c b t d.
Distributor p =>
(s -> Either a c)
-> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t
dialt s -> Either a c
f b -> t
g d -> t
h p a b
p p c d
q = (s -> Either a c)
-> (Either b d -> t) -> p (Either a c) (Either b d) -> p s t
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap s -> Either a c
f ((b -> t) -> (d -> t) -> Either b d -> t
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either b -> t
g d -> t
h) (p a b
p p a b -> p c d -> p (Either a c) (Either b d)
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p c d
q)

{- | A class of `Homogeneous`
countable sums of countable products.
-}
class Traversable t => Homogeneous t where
  {- | Sequences actions `homogeneously`.

  prop> homogeneously @Maybe = optionalP
  prop> homogeneously @[] = manyP

  Any `Traversable` & `Data.Distributive.Distributive` countable product
  can be given a default implementation for the `homogeneously` method.

  prop> homogeneously = ditraverse

  And any user-defined homogeneous algebraic datatype has
  a default instance for `Homogeneous`, by deriving `Generic1`.
  -}
  homogeneously :: Distributor p => p a b -> p (t a) (t b)
  default homogeneously
    :: (Generic1 t, Homogeneous (Rep1 t), Distributor p)
    => p a b -> p (t a) (t b)
  homogeneously = (t a -> Rep1 t a)
-> (Rep1 t b -> t b) -> p (Rep1 t a) (Rep1 t b) -> p (t a) (t b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap t a -> Rep1 t a
forall a. t a -> Rep1 t a
forall k (f :: k -> *) (a :: k). Generic1 f => f a -> Rep1 f a
from1 Rep1 t b -> t b
forall a. Rep1 t a -> t a
forall k (f :: k -> *) (a :: k). Generic1 f => Rep1 f a -> f a
to1 (p (Rep1 t a) (Rep1 t b) -> p (t a) (t b))
-> (p a b -> p (Rep1 t a) (Rep1 t b)) -> p a b -> p (t a) (t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (Rep1 t a) (Rep1 t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Rep1 t a) (Rep1 t b)
homogeneously
instance Homogeneous Par1 where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Par1 a) (Par1 b)
homogeneously = (Par1 a -> a) -> (b -> Par1 b) -> p a b -> p (Par1 a) (Par1 b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Par1 a -> a
forall p. Par1 p -> p
unPar1 b -> Par1 b
forall p. p -> Par1 p
Par1
instance Homogeneous Identity where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Identity a) (Identity b)
homogeneously = (Identity a -> a)
-> (b -> Identity b) -> p a b -> p (Identity a) (Identity b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Identity a -> a
forall a. Identity a -> a
runIdentity b -> Identity b
forall a. a -> Identity a
Identity
instance Homogeneous Monoid.Dual where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Dual a) (Dual b)
homogeneously = (Dual a -> a) -> (b -> Dual b) -> p a b -> p (Dual a) (Dual b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Dual a -> a
forall a. Dual a -> a
Monoid.getDual b -> Dual b
forall a. a -> Dual a
Monoid.Dual
instance Homogeneous Monoid.Product where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Product a) (Product b)
homogeneously = (Product a -> a)
-> (b -> Product b) -> p a b -> p (Product a) (Product b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Product a -> a
forall a. Product a -> a
Monoid.getProduct b -> Product b
forall a. a -> Product a
Monoid.Product
instance Homogeneous Monoid.Sum where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Sum a) (Sum b)
homogeneously = (Sum a -> a) -> (b -> Sum b) -> p a b -> p (Sum a) (Sum b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Sum a -> a
forall a. Sum a -> a
Monoid.getSum b -> Sum b
forall a. a -> Sum a
Monoid.Sum
instance Homogeneous (Tagged s) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Tagged s a) (Tagged s b)
homogeneously = (Tagged s a -> a)
-> (b -> Tagged s b) -> p a b -> p (Tagged s a) (Tagged s b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Tagged s a -> a
forall {k} (s :: k) b. Tagged s b -> b
unTagged b -> Tagged s b
forall {k} (s :: k) b. b -> Tagged s b
Tagged
instance Homogeneous U1 where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (U1 a) (U1 b)
homogeneously p a b
_ = U1 b -> p (U1 a) (U1 b)
forall a. a -> p (U1 a) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure U1 b
forall k (p :: k). U1 p
U1
instance Homogeneous (K1 i ()) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (K1 i () a) (K1 i () b)
homogeneously p a b
_ = K1 i () b -> p (K1 i () a) (K1 i () b)
forall a. a -> p (K1 i () a) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> K1 i () b
forall k i c (p :: k). c -> K1 i c p
K1 ())
instance Homogeneous (Const ()) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Const () a) (Const () b)
homogeneously p a b
_ = Const () b -> p (Const () a) (Const () b)
forall a. a -> p (Const () a) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (() -> Const () b
forall {k} a (b :: k). a -> Const a b
Const ())
instance Homogeneous Proxy where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Proxy a) (Proxy b)
homogeneously p a b
_ = Proxy b -> p (Proxy a) (Proxy b)
forall a. a -> p (Proxy a) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Proxy b
forall {k} (t :: k). Proxy t
Proxy
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (s :.: t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p ((:.:) s t a) ((:.:) s t b)
homogeneously
      = ((:.:) s t a -> s (t a))
-> (s (t b) -> (:.:) s t b)
-> p (s (t a)) (s (t b))
-> p ((:.:) s t a) ((:.:) s t b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (:.:) s t a -> s (t a)
forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
(:.:) f g p -> f (g p)
unComp1 s (t b) -> (:.:) s t b
forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1
      (p (s (t a)) (s (t b)) -> p ((:.:) s t a) ((:.:) s t b))
-> (p a b -> p (s (t a)) (s (t b)))
-> p a b
-> p ((:.:) s t a) ((:.:) s t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (t a) (t b) -> p (s (t a)) (s (t b))
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously (p (t a) (t b) -> p (s (t a)) (s (t b)))
-> (p a b -> p (t a) (t b)) -> p a b -> p (s (t a)) (s (t b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (Compose s t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Compose s t a) (Compose s t b)
homogeneously
      = (Compose s t a -> s (t a))
-> (s (t b) -> Compose s t b)
-> p (s (t a)) (s (t b))
-> p (Compose s t a) (Compose s t b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Compose s t a -> s (t a)
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose s (t b) -> Compose s t b
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose
      (p (s (t a)) (s (t b)) -> p (Compose s t a) (Compose s t b))
-> (p a b -> p (s (t a)) (s (t b)))
-> p a b
-> p (Compose s t a) (Compose s t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p (t a) (t b) -> p (s (t a)) (s (t b))
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously (p (t a) (t b) -> p (s (t a)) (s (t b)))
-> (p a b -> p (t a) (t b)) -> p a b -> p (s (t a)) (s (t b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (s :*: t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p ((:*:) s t a) ((:*:) s t b)
homogeneously p a b
p = ((:*:) s t a -> s a)
-> ((:*:) s t a -> t a)
-> (s b -> t b -> (:*:) s t b)
-> p (s a) (s b)
-> p (t a) (t b)
-> p ((:*:) s t a) ((:*:) s t b)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2
      (\(s a
s :*: t a
_) -> s a
s)
      (\(s a
_ :*: t a
t) -> t a
t)
      s b -> t b -> (:*:) s t b
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:)
      (p a b -> p (s a) (s b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously p a b
p)
      (p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously p a b
p)
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (Functor.Product s t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Product s t a) (Product s t b)
homogeneously p a b
p = (Product s t a -> s a)
-> (Product s t a -> t a)
-> (s b -> t b -> Product s t b)
-> p (s a) (s b)
-> p (t a) (t b)
-> p (Product s t a) (Product s t b)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2
      (\(Functor.Pair s a
s t a
_) -> s a
s)
      (\(Functor.Pair s a
_ t a
t) -> t a
t)
      s b -> t b -> Product s t b
forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Functor.Pair
      (p a b -> p (s a) (s b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously p a b
p)
      (p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously p a b
p)
instance Homogeneous V1 where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (V1 a) (V1 b)
homogeneously p a b
_ = (V1 a -> Void) -> (Void -> V1 b) -> p Void Void -> p (V1 a) (V1 b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap (V1 a -> Void
\case) (Void -> V1 b
\case) p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
instance Homogeneous (K1 i Void) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (K1 i Void a) (K1 i Void b)
homogeneously p a b
_ = (K1 i Void a -> Void)
-> (Void -> K1 i Void b)
-> p Void Void
-> p (K1 i Void a) (K1 i Void b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap K1 i Void a -> Void
forall k i c (p :: k). K1 i c p -> c
unK1 Void -> K1 i Void b
forall k i c (p :: k). c -> K1 i c p
K1 p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
instance Homogeneous (Const Void) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Const Void a) (Const Void b)
homogeneously p a b
_ = (Const Void a -> Void)
-> (Void -> Const Void b)
-> p Void Void
-> p (Const Void a) (Const Void b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Const Void a -> Void
forall {k} a (b :: k). Const a b -> a
getConst Void -> Const Void b
forall {k} a (b :: k). a -> Const a b
Const p Void Void
forall (p :: * -> * -> *). Distributor p => p Void Void
zeroP
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (s :+: t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p ((:+:) s t a) ((:+:) s t b)
homogeneously p a b
p = ((:+:) s t a -> Either (s a) (t a))
-> (s b -> (:+:) s t b)
-> (t b -> (:+:) s t b)
-> p (s a) (s b)
-> p (t a) (t b)
-> p ((:+:) s t a) ((:+:) s t b)
forall (p :: * -> * -> *) s a c b t d.
Distributor p =>
(s -> Either a c)
-> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t
dialt
      (\case {L1 s a
s -> s a -> Either (s a) (t a)
forall a b. a -> Either a b
Left s a
s; R1 t a
t -> t a -> Either (s a) (t a)
forall a b. b -> Either a b
Right t a
t})
      s b -> (:+:) s t b
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1
      t b -> (:+:) s t b
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1
      (p a b -> p (s a) (s b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously p a b
p)
      (p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously p a b
p)
instance (Homogeneous s, Homogeneous t)
  => Homogeneous (Functor.Sum s t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Sum s t a) (Sum s t b)
homogeneously p a b
p = (Sum s t a -> Either (s a) (t a))
-> (s b -> Sum s t b)
-> (t b -> Sum s t b)
-> p (s a) (s b)
-> p (t a) (t b)
-> p (Sum s t a) (Sum s t b)
forall (p :: * -> * -> *) s a c b t d.
Distributor p =>
(s -> Either a c)
-> (b -> t) -> (d -> t) -> p a b -> p c d -> p s t
dialt
      (\case {Functor.InL s a
s -> s a -> Either (s a) (t a)
forall a b. a -> Either a b
Left s a
s; Functor.InR t a
t -> t a -> Either (s a) (t a)
forall a b. b -> Either a b
Right t a
t})
      s b -> Sum s t b
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
Functor.InL
      t b -> Sum s t b
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
Functor.InR
      (p a b -> p (s a) (s b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (s a) (s b)
homogeneously p a b
p)
      (p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously p a b
p)
instance Homogeneous t
  => Homogeneous (M1 i c t) where
    homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (M1 i c t a) (M1 i c t b)
homogeneously = (M1 i c t a -> t a)
-> (t b -> M1 i c t b)
-> p (t a) (t b)
-> p (M1 i c t a) (M1 i c t b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap M1 i c t a -> t a
forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1 t b -> M1 i c t b
forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 (p (t a) (t b) -> p (M1 i c t a) (M1 i c t b))
-> (p a b -> p (t a) (t b)) -> p a b -> p (M1 i c t a) (M1 i c t b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (t a) (t b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (t a) (t b)
homogeneously
instance Homogeneous f => Homogeneous (Rec1 f) where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Rec1 f a) (Rec1 f b)
homogeneously = (Rec1 f a -> f a)
-> (f b -> Rec1 f b) -> p (f a) (f b) -> p (Rec1 f a) (Rec1 f b)
forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d
forall (p :: * -> * -> *) a b c d.
Profunctor p =>
(a -> b) -> (c -> d) -> p b c -> p a d
dimap Rec1 f a -> f a
forall k (f :: k -> *) (p :: k). Rec1 f p -> f p
unRec1 f b -> Rec1 f b
forall k (f :: k -> *) (p :: k). f p -> Rec1 f p
Rec1 (p (f a) (f b) -> p (Rec1 f a) (Rec1 f b))
-> (p a b -> p (f a) (f b)) -> p a b -> p (Rec1 f a) (Rec1 f b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p (f a) (f b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (f a) (f b)
homogeneously
instance Homogeneous Maybe where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
homogeneously = p a b -> p (Maybe a) (Maybe b)
forall a b. p a b -> p (Maybe a) (Maybe b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Maybe a) (Maybe b)
optionalP
instance Homogeneous [] where
  homogeneously :: forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
homogeneously = p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP
instance Homogeneous Vector where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Vector a) (Vector b)
homogeneously p a b
p = Exchange
  (Either () (a, Vector a))
  (Either () (b, Vector b))
  (Either () (a, Vector a))
  (Identity (Either () (b, Vector b)))
-> Exchange
     (Either () (a, Vector a))
     (Either () (b, Vector b))
     (Vector a)
     (Identity (Vector b))
forall s a t b.
(Cons s s a a, AsEmpty t, Cons t t b b) =>
Iso s t (Either () (a, s)) (Either () (b, t))
Iso
  (Vector a)
  (Vector b)
  (Either () (a, Vector a))
  (Either () (b, Vector b))
eotList (Exchange
   (Either () (a, Vector a))
   (Either () (b, Vector b))
   (Either () (a, Vector a))
   (Identity (Either () (b, Vector b)))
 -> Exchange
      (Either () (a, Vector a))
      (Either () (b, Vector b))
      (Vector a)
      (Identity (Vector b)))
-> p (Either () (a, Vector a)) (Either () (b, Vector b))
-> p (Vector a) (Vector b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () ()
-> p (a, Vector a) (b, Vector b)
-> p (Either () (a, Vector a)) (Either () (b, Vector b))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a b
p p a b -> p (Vector a) (Vector b) -> p (a, Vector a) (b, Vector b)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b -> p (Vector a) (Vector b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Vector a) (Vector b)
homogeneously p a b
p
instance Homogeneous Seq where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Seq a) (Seq b)
homogeneously p a b
p = Exchange
  (Either () (a, Seq a))
  (Either () (b, Seq b))
  (Either () (a, Seq a))
  (Identity (Either () (b, Seq b)))
-> Exchange
     (Either () (a, Seq a))
     (Either () (b, Seq b))
     (Seq a)
     (Identity (Seq b))
forall s a t b.
(Cons s s a a, AsEmpty t, Cons t t b b) =>
Iso s t (Either () (a, s)) (Either () (b, t))
Iso (Seq a) (Seq b) (Either () (a, Seq a)) (Either () (b, Seq b))
eotList (Exchange
   (Either () (a, Seq a))
   (Either () (b, Seq b))
   (Either () (a, Seq a))
   (Identity (Either () (b, Seq b)))
 -> Exchange
      (Either () (a, Seq a))
      (Either () (b, Seq b))
      (Seq a)
      (Identity (Seq b)))
-> p (Either () (a, Seq a)) (Either () (b, Seq b))
-> p (Seq a) (Seq b)
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~ p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () ()
-> p (a, Seq a) (b, Seq b)
-> p (Either () (a, Seq a)) (Either () (b, Seq b))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p a b
p p a b -> p (Seq a) (Seq b) -> p (a, Seq a) (b, Seq b)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b -> p (Seq a) (Seq b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Seq a) (Seq b)
homogeneously p a b
p
instance Homogeneous Complex where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Complex a) (Complex b)
homogeneously p a b
p = (Complex a -> a)
-> (Complex a -> a)
-> (b -> b -> Complex b)
-> p a b
-> p a b
-> p (Complex a) (Complex b)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2 Complex a -> a
forall a. Complex a -> a
realPart Complex a -> a
forall a. Complex a -> a
imagPart b -> b -> Complex b
forall a. a -> a -> Complex a
(:+) p a b
p p a b
p
instance Homogeneous Tree where
  homogeneously :: forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Tree a) (Tree b)
homogeneously p a b
p = (Tree a -> a)
-> (Tree a -> [Tree a])
-> (b -> [Tree b] -> Tree b)
-> p a b
-> p [Tree a] [Tree b]
-> p (Tree a) (Tree b)
forall (p :: * -> * -> *) s a c b d t.
Monoidal p =>
(s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t
dimap2 Tree a -> a
forall a. Tree a -> a
rootLabel Tree a -> [Tree a]
forall a. Tree a -> [Tree a]
subForest b -> [Tree b] -> Tree b
forall a. a -> [Tree a] -> Tree a
Node p a b
p (p (Tree a) (Tree b) -> p [Tree a] [Tree b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b -> p (Tree a) (Tree b)
forall (t :: * -> *) (p :: * -> * -> *) a b.
(Homogeneous t, Distributor p) =>
p a b -> p (t a) (t b)
forall (p :: * -> * -> *) a b.
Distributor p =>
p a b -> p (Tree a) (Tree b)
homogeneously p a b
p))

-- Alternator --

{- | 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 `Functor`s the analog of `alternate` can be defined
without any other constraint, but the case of `Profunctor`s turns
out to be slighly more complex.
-}
class (Choice p, Distributor p, forall x. Alternative (p x))
  => Alternator p where

    {- |
    prop> left' = alternate . Left
    prop> right' = alternate . Right
    prop> zeroP = empty
    prop> x >+< y = alternate (Left x) <|> alternate (Right y)

    `alternate` has a default for `Cochoice`.
    -}
    alternate
      :: Either (p a b) (p c d)
      -> p (Either a c) (Either b d)
    default alternate
      :: Cochoice p
      => Either (p a b) (p c d)
      -> p (Either a c) (Either b d)
    alternate =
      (Either a c -> Maybe a)
-> (b -> Maybe (Either b d))
-> p a b
-> p (Either a c) (Either b d)
forall (p :: * -> * -> *) s a b t.
(Choice p, Cochoice p) =>
(s -> Maybe a) -> (b -> Maybe t) -> p a b -> p s t
dimapMaybe ((a -> Maybe a) -> (c -> Maybe a) -> Either a c -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> Maybe a
forall a. a -> Maybe a
Just (Maybe a -> c -> Maybe a
forall a. a -> c -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)) (Either b d -> Maybe (Either b d)
forall a. a -> Maybe a
Just (Either b d -> Maybe (Either b d))
-> (b -> Either b d) -> b -> Maybe (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b d
forall a b. a -> Either a b
Left)
      (p a b -> p (Either a c) (Either b d))
-> (p c d -> p (Either a c) (Either b d))
-> Either (p a b) (p c d)
-> p (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
a b d -> a c d -> a (Either b c) d
|||
      (Either a c -> Maybe c)
-> (d -> Maybe (Either b d))
-> p c d
-> p (Either a c) (Either b d)
forall (p :: * -> * -> *) s a b t.
(Choice p, Cochoice p) =>
(s -> Maybe a) -> (b -> Maybe t) -> p a b -> p s t
dimapMaybe ((a -> Maybe c) -> (c -> Maybe c) -> Either a c -> Maybe c
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe c -> a -> Maybe c
forall a. a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe c
forall a. Maybe a
Nothing) c -> Maybe c
forall a. a -> Maybe a
Just) (Either b d -> Maybe (Either b d)
forall a. a -> Maybe a
Just (Either b d -> Maybe (Either b d))
-> (d -> Either b d) -> d -> Maybe (Either b d)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. d -> Either b d
forall a b. b -> Either a b
Right)

    {- | One or more. -}
    someP :: p a b -> p [a] [b]
    someP p a b
p = Market (a, [a]) (b, [b]) (a, [a]) (Identity (b, [b]))
-> Market (a, [a]) (b, [b]) [a] (Identity [b])
forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
Prism [a] [b] (a, [a]) (b, [b])
_Cons (Market (a, [a]) (b, [b]) (a, [a]) (Identity (b, [b]))
 -> Market (a, [a]) (b, [b]) [a] (Identity [b]))
-> p (a, [a]) (b, [b]) -> p [a] [b]
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p a b
p p a b -> p [a] [b] -> p (a, [a]) (b, [b])
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP p a b
p

-- | Combines all `Alternative` choices in the specified list.
choice :: (Foldable f, Alternative p) => f (p a) -> p a
choice :: forall (f :: * -> *) (p :: * -> *) a.
(Foldable f, Alternative p) =>
f (p a) -> p a
choice = (p a -> p a -> p a) -> p a -> f (p a) -> p a
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' p a -> p a -> p a
forall a. p a -> p a -> p a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) p a
forall a. p a
forall (f :: * -> *) a. Alternative f => f a
empty

-- | Perform an `Alternative` action or return a default value.
option :: Alternative p => a {- ^ default value -} -> p a -> p a
option :: forall (p :: * -> *) a. Alternative p => a -> p a -> p a
option a
a p a
p = p a
p p a -> p a -> p a
forall a. p a -> p a -> p a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> p a
forall a. a -> p a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a

instance (Alternator p, Applicative f)
  => Alternator (WrappedPafb f p) where
    alternate :: forall a b c d.
Either (WrappedPafb f p a b) (WrappedPafb f p c d)
-> WrappedPafb f p (Either a c) (Either b d)
alternate =
      let
        f :: WrappedPafb f p a a -> WrappedPafb f p (Either a c) (Either a b)
f = p (Either a c) (f (Either a b))
-> WrappedPafb f p (Either a c) (Either a b)
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb
          (p (Either a c) (f (Either a b))
 -> WrappedPafb f p (Either a c) (Either a b))
-> (WrappedPafb f p a a -> p (Either a c) (f (Either a b)))
-> WrappedPafb f p a a
-> WrappedPafb f p (Either a c) (Either a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (f a) (Either a b) -> f (Either a b))
-> p (Either a c) (Either (f a) (Either a b))
-> p (Either a c) (f (Either a b))
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap ((f a -> f (Either a b))
-> (Either a b -> f (Either a b))
-> Either (f a) (Either a b)
-> f (Either a b)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((a -> Either a b) -> f a -> f (Either a b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Either a b
forall a b. a -> Either a b
Left) Either a b -> f (Either a b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
          (p (Either a c) (Either (f a) (Either a b))
 -> p (Either a c) (f (Either a b)))
-> (WrappedPafb f p a a
    -> p (Either a c) (Either (f a) (Either a b)))
-> WrappedPafb f p a a
-> p (Either a c) (f (Either a b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either (p a (f a)) (p c (Either a b))
-> p (Either a c) (Either (f a) (Either a b))
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate
          (Either (p a (f a)) (p c (Either a b))
 -> p (Either a c) (Either (f a) (Either a b)))
-> (WrappedPafb f p a a -> Either (p a (f a)) (p c (Either a b)))
-> WrappedPafb f p a a
-> p (Either a c) (Either (f a) (Either a b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a (f a) -> Either (p a (f a)) (p c (Either a b))
forall a b. a -> Either a b
Left
          (p a (f a) -> Either (p a (f a)) (p c (Either a b)))
-> (WrappedPafb f p a a -> p a (f a))
-> WrappedPafb f p a a
-> Either (p a (f a)) (p c (Either a b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedPafb f p a a -> p a (f a)
forall (f :: * -> *) (p :: * -> * -> *) a b.
WrappedPafb f p a b -> p a (f b)
unwrapPafb
        g :: WrappedPafb f p c b -> WrappedPafb f p (Either a c) (Either a b)
g = p (Either a c) (f (Either a b))
-> WrappedPafb f p (Either a c) (Either a b)
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb
          (p (Either a c) (f (Either a b))
 -> WrappedPafb f p (Either a c) (Either a b))
-> (WrappedPafb f p c b -> p (Either a c) (f (Either a b)))
-> WrappedPafb f p c b
-> WrappedPafb f p (Either a c) (Either a b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either (Either a b) (f b) -> f (Either a b))
-> p (Either a c) (Either (Either a b) (f b))
-> p (Either a c) (f (Either a b))
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap ((Either a b -> f (Either a b))
-> (f b -> f (Either a b))
-> Either (Either a b) (f b)
-> f (Either a b)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Either a b -> f (Either a b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((b -> Either a b) -> f b -> f (Either a b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either a b
forall a b. b -> Either a b
Right))
          (p (Either a c) (Either (Either a b) (f b))
 -> p (Either a c) (f (Either a b)))
-> (WrappedPafb f p c b
    -> p (Either a c) (Either (Either a b) (f b)))
-> WrappedPafb f p c b
-> p (Either a c) (f (Either a b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either (p a (Either a b)) (p c (f b))
-> p (Either a c) (Either (Either a b) (f b))
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate
          (Either (p a (Either a b)) (p c (f b))
 -> p (Either a c) (Either (Either a b) (f b)))
-> (WrappedPafb f p c b -> Either (p a (Either a b)) (p c (f b)))
-> WrappedPafb f p c b
-> p (Either a c) (Either (Either a b) (f b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p c (f b) -> Either (p a (Either a b)) (p c (f b))
forall a b. b -> Either a b
Right
          (p c (f b) -> Either (p a (Either a b)) (p c (f b)))
-> (WrappedPafb f p c b -> p c (f b))
-> WrappedPafb f p c b
-> Either (p a (Either a b)) (p c (f b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrappedPafb f p c b -> p c (f b)
forall (f :: * -> *) (p :: * -> * -> *) a b.
WrappedPafb f p a b -> p a (f b)
unwrapPafb
      in
        (WrappedPafb f p a b -> WrappedPafb f p (Either a c) (Either b d))
-> (WrappedPafb f p c d
    -> WrappedPafb f p (Either a c) (Either b d))
-> Either (WrappedPafb f p a b) (WrappedPafb f p c d)
-> WrappedPafb f p (Either a c) (Either b d)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either WrappedPafb f p a b -> WrappedPafb f p (Either a c) (Either b d)
forall {a} {a} {c} {b}.
WrappedPafb f p a a -> WrappedPafb f p (Either a c) (Either a b)
f WrappedPafb f p c d -> WrappedPafb f p (Either a c) (Either b d)
forall {c} {b} {a} {a}.
WrappedPafb f p c b -> WrappedPafb f p (Either a c) (Either a b)
g

    someP :: forall a b. WrappedPafb f p a b -> WrappedPafb f p [a] [b]
someP (WrapPafb p a (f b)
x) = p [a] (f [b]) -> WrappedPafb f p [a] [b]
forall (f :: * -> *) (p :: * -> * -> *) a b.
p a (f b) -> WrappedPafb f p a b
WrapPafb (([f b] -> f [b]) -> p [a] [f b] -> p [a] (f [b])
forall b c a. (b -> c) -> p a b -> p a c
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap [f b] -> f [b]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA (p a (f b) -> p [a] [f b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP p a (f b)
x))
instance Alternator p => Alternator (Coyoneda p) where
  alternate :: forall a b c d.
Either (Coyoneda p a b) (Coyoneda p c d)
-> Coyoneda p (Either a c) (Either b d)
alternate (Left Coyoneda p a b
p) = p (Either a c) (Either b d) -> Coyoneda p (Either a c) (Either b d)
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p a b -> Either (p a b) (p c d)
forall a b. a -> Either a b
Left (Coyoneda p a b -> p a b
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Coyoneda p a b
p)))
  alternate (Right Coyoneda p c d
p) = p (Either a c) (Either b d) -> Coyoneda p (Either a c) (Either b d)
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p c d -> Either (p a b) (p c d)
forall a b. b -> Either a b
Right (Coyoneda p c d -> p c d
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Coyoneda p c d
p)))
  someP :: forall a b. Coyoneda p a b -> Coyoneda p [a] [b]
someP = p [a] [b] -> Coyoneda p [a] [b]
p :-> Coyoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Coyoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p [a] [b] -> Coyoneda p [a] [b])
-> (Coyoneda p a b -> p [a] [b])
-> Coyoneda p a b
-> Coyoneda p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP (p a b -> p [a] [b])
-> (Coyoneda p a b -> p a b) -> Coyoneda p a b -> p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Coyoneda p a b -> p a b
Coyoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Coyoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract
instance Alternator p => Alternator (Yoneda p) where
  alternate :: forall a b c d.
Either (Yoneda p a b) (Yoneda p c d)
-> Yoneda p (Either a c) (Either b d)
alternate (Left Yoneda p a b
p) = p (Either a c) (Either b d) -> Yoneda p (Either a c) (Either b d)
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p a b -> Either (p a b) (p c d)
forall a b. a -> Either a b
Left (Yoneda p a b -> p a b
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Yoneda p a b
p)))
  alternate (Right Yoneda p c d
p) = p (Either a c) (Either b d) -> Yoneda p (Either a c) (Either b d)
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall a b c d.
Either (p a b) (p c d) -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Alternator p =>
Either (p a b) (p c d) -> p (Either a c) (Either b d)
alternate (p c d -> Either (p a b) (p c d)
forall a b. b -> Either a b
Right (Yoneda p c d -> p c d
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract Yoneda p c d
p)))
  someP :: forall a b. Yoneda p a b -> Yoneda p [a] [b]
someP = p [a] [b] -> Yoneda p [a] [b]
p :-> Yoneda p
forall (p :: * -> * -> *). Profunctor p => p :-> Yoneda p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorMonad t, Profunctor p) =>
p :-> t p
proreturn (p [a] [b] -> Yoneda p [a] [b])
-> (Yoneda p a b -> p [a] [b]) -> Yoneda p a b -> Yoneda p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Alternator p => p a b -> p [a] [b]
someP (p a b -> p [a] [b])
-> (Yoneda p a b -> p a b) -> Yoneda p a b -> p [a] [b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Yoneda p a b -> p a b
Yoneda p :-> p
forall (p :: * -> * -> *). Profunctor p => Yoneda p :-> p
forall (t :: (* -> * -> *) -> * -> * -> *) (p :: * -> * -> *).
(ProfunctorComonad t, Profunctor p) =>
t p :-> p
proextract

{- | Used to sequence multiple times,
separated by a `separateBy`,
begun by a `beginBy`,
and ended by an `endBy`. -}
data SepBy p = SepBy
  { forall p. SepBy p -> p
beginBy :: p
  , forall p. SepBy p -> p
endBy :: p
  , forall p. SepBy p -> p
separateBy :: p
  } deriving stock
    ( (forall a b. (a -> b) -> SepBy a -> SepBy b)
-> (forall a b. a -> SepBy b -> SepBy a) -> Functor SepBy
forall a b. a -> SepBy b -> SepBy a
forall a b. (a -> b) -> SepBy a -> SepBy b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> SepBy a -> SepBy b
fmap :: forall a b. (a -> b) -> SepBy a -> SepBy b
$c<$ :: forall a b. a -> SepBy b -> SepBy a
<$ :: forall a b. a -> SepBy b -> SepBy a
Functor, (forall m. Monoid m => SepBy m -> m)
-> (forall m a. Monoid m => (a -> m) -> SepBy a -> m)
-> (forall m a. Monoid m => (a -> m) -> SepBy a -> m)
-> (forall a b. (a -> b -> b) -> b -> SepBy a -> b)
-> (forall a b. (a -> b -> b) -> b -> SepBy a -> b)
-> (forall b a. (b -> a -> b) -> b -> SepBy a -> b)
-> (forall b a. (b -> a -> b) -> b -> SepBy a -> b)
-> (forall a. (a -> a -> a) -> SepBy a -> a)
-> (forall a. (a -> a -> a) -> SepBy a -> a)
-> (forall a. SepBy a -> [a])
-> (forall a. SepBy a -> Bool)
-> (forall a. SepBy a -> Int)
-> (forall a. Eq a => a -> SepBy a -> Bool)
-> (forall a. Ord a => SepBy a -> a)
-> (forall a. Ord a => SepBy a -> a)
-> (forall a. Num a => SepBy a -> a)
-> (forall a. Num a => SepBy a -> a)
-> Foldable SepBy
forall a. Eq a => a -> SepBy a -> Bool
forall a. Num a => SepBy a -> a
forall a. Ord a => SepBy a -> a
forall m. Monoid m => SepBy m -> m
forall a. SepBy a -> Bool
forall a. SepBy a -> Int
forall a. SepBy a -> [a]
forall a. (a -> a -> a) -> SepBy a -> a
forall m a. Monoid m => (a -> m) -> SepBy a -> m
forall b a. (b -> a -> b) -> b -> SepBy a -> b
forall a b. (a -> b -> b) -> b -> SepBy a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => SepBy m -> m
fold :: forall m. Monoid m => SepBy m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> SepBy a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> SepBy a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> SepBy a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> SepBy a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> SepBy a -> b
foldr :: forall a b. (a -> b -> b) -> b -> SepBy a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> SepBy a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> SepBy a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> SepBy a -> b
foldl :: forall b a. (b -> a -> b) -> b -> SepBy a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> SepBy a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> SepBy a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> SepBy a -> a
foldr1 :: forall a. (a -> a -> a) -> SepBy a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> SepBy a -> a
foldl1 :: forall a. (a -> a -> a) -> SepBy a -> a
$ctoList :: forall a. SepBy a -> [a]
toList :: forall a. SepBy a -> [a]
$cnull :: forall a. SepBy a -> Bool
null :: forall a. SepBy a -> Bool
$clength :: forall a. SepBy a -> Int
length :: forall a. SepBy a -> Int
$celem :: forall a. Eq a => a -> SepBy a -> Bool
elem :: forall a. Eq a => a -> SepBy a -> Bool
$cmaximum :: forall a. Ord a => SepBy a -> a
maximum :: forall a. Ord a => SepBy a -> a
$cminimum :: forall a. Ord a => SepBy a -> a
minimum :: forall a. Ord a => SepBy a -> a
$csum :: forall a. Num a => SepBy a -> a
sum :: forall a. Num a => SepBy a -> a
$cproduct :: forall a. Num a => SepBy a -> a
product :: forall a. Num a => SepBy a -> a
Foldable, Functor SepBy
Foldable SepBy
(Functor SepBy, Foldable SepBy) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> SepBy a -> f (SepBy b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    SepBy (f a) -> f (SepBy a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> SepBy a -> m (SepBy b))
-> (forall (m :: * -> *) a. Monad m => SepBy (m a) -> m (SepBy a))
-> Traversable SepBy
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => SepBy (m a) -> m (SepBy a)
forall (f :: * -> *) a. Applicative f => SepBy (f a) -> f (SepBy a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SepBy a -> m (SepBy b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SepBy a -> f (SepBy b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SepBy a -> f (SepBy b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SepBy a -> f (SepBy b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => SepBy (f a) -> f (SepBy a)
sequenceA :: forall (f :: * -> *) a. Applicative f => SepBy (f a) -> f (SepBy a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SepBy a -> m (SepBy b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> SepBy a -> m (SepBy b)
$csequence :: forall (m :: * -> *) a. Monad m => SepBy (m a) -> m (SepBy a)
sequence :: forall (m :: * -> *) a. Monad m => SepBy (m a) -> m (SepBy a)
Traversable
    , SepBy p -> SepBy p -> Bool
(SepBy p -> SepBy p -> Bool)
-> (SepBy p -> SepBy p -> Bool) -> Eq (SepBy p)
forall p. Eq p => SepBy p -> SepBy p -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall p. Eq p => SepBy p -> SepBy p -> Bool
== :: SepBy p -> SepBy p -> Bool
$c/= :: forall p. Eq p => SepBy p -> SepBy p -> Bool
/= :: SepBy p -> SepBy p -> Bool
Eq, Eq (SepBy p)
Eq (SepBy p) =>
(SepBy p -> SepBy p -> Ordering)
-> (SepBy p -> SepBy p -> Bool)
-> (SepBy p -> SepBy p -> Bool)
-> (SepBy p -> SepBy p -> Bool)
-> (SepBy p -> SepBy p -> Bool)
-> (SepBy p -> SepBy p -> SepBy p)
-> (SepBy p -> SepBy p -> SepBy p)
-> Ord (SepBy p)
SepBy p -> SepBy p -> Bool
SepBy p -> SepBy p -> Ordering
SepBy p -> SepBy p -> SepBy p
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall p. Ord p => Eq (SepBy p)
forall p. Ord p => SepBy p -> SepBy p -> Bool
forall p. Ord p => SepBy p -> SepBy p -> Ordering
forall p. Ord p => SepBy p -> SepBy p -> SepBy p
$ccompare :: forall p. Ord p => SepBy p -> SepBy p -> Ordering
compare :: SepBy p -> SepBy p -> Ordering
$c< :: forall p. Ord p => SepBy p -> SepBy p -> Bool
< :: SepBy p -> SepBy p -> Bool
$c<= :: forall p. Ord p => SepBy p -> SepBy p -> Bool
<= :: SepBy p -> SepBy p -> Bool
$c> :: forall p. Ord p => SepBy p -> SepBy p -> Bool
> :: SepBy p -> SepBy p -> Bool
$c>= :: forall p. Ord p => SepBy p -> SepBy p -> Bool
>= :: SepBy p -> SepBy p -> Bool
$cmax :: forall p. Ord p => SepBy p -> SepBy p -> SepBy p
max :: SepBy p -> SepBy p -> SepBy p
$cmin :: forall p. Ord p => SepBy p -> SepBy p -> SepBy p
min :: SepBy p -> SepBy p -> SepBy p
Ord, Int -> SepBy p -> ShowS
[SepBy p] -> ShowS
SepBy p -> String
(Int -> SepBy p -> ShowS)
-> (SepBy p -> String) -> ([SepBy p] -> ShowS) -> Show (SepBy p)
forall p. Show p => Int -> SepBy p -> ShowS
forall p. Show p => [SepBy p] -> ShowS
forall p. Show p => SepBy p -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall p. Show p => Int -> SepBy p -> ShowS
showsPrec :: Int -> SepBy p -> ShowS
$cshow :: forall p. Show p => SepBy p -> String
show :: SepBy p -> String
$cshowList :: forall p. Show p => [SepBy p] -> ShowS
showList :: [SepBy p] -> ShowS
Show, ReadPrec [SepBy p]
ReadPrec (SepBy p)
Int -> ReadS (SepBy p)
ReadS [SepBy p]
(Int -> ReadS (SepBy p))
-> ReadS [SepBy p]
-> ReadPrec (SepBy p)
-> ReadPrec [SepBy p]
-> Read (SepBy p)
forall p. Read p => ReadPrec [SepBy p]
forall p. Read p => ReadPrec (SepBy p)
forall p. Read p => Int -> ReadS (SepBy p)
forall p. Read p => ReadS [SepBy p]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall p. Read p => Int -> ReadS (SepBy p)
readsPrec :: Int -> ReadS (SepBy p)
$creadList :: forall p. Read p => ReadS [SepBy p]
readList :: ReadS [SepBy p]
$creadPrec :: forall p. Read p => ReadPrec (SepBy p)
readPrec :: ReadPrec (SepBy p)
$creadListPrec :: forall p. Read p => ReadPrec [SepBy p]
readListPrec :: ReadPrec [SepBy p]
Read
    )

{- | A `SepBy` smart constructor,
setting the `separateBy` field,
with no beginning or ending delimitors,
except by updating `beginBy` or `endBy` fields. -}
sepBy :: Monoidal p => p () () -> SepBy (p () ())
sepBy :: forall (p :: * -> * -> *). Monoidal p => p () () -> SepBy (p () ())
sepBy = p () () -> p () () -> p () () -> SepBy (p () ())
forall p. p -> p -> p -> SepBy p
SepBy p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP

{- | A `SepBy` smart constructor for no separator,
beginning or ending delimiters. -}
noSep :: Monoidal p => SepBy (p () ())
noSep :: forall (p :: * -> * -> *). Monoidal p => SepBy (p () ())
noSep = p () () -> SepBy (p () ())
forall (p :: * -> * -> *). Monoidal p => p () () -> SepBy (p () ())
sepBy p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP

{- |
prop> several noSep = manyP
-}
several
  :: (IsList s, IsList t, Distributor p)
  => SepBy (p () ()) -> p (Item s) (Item t) -> p s t
several :: forall s t (p :: * -> * -> *).
(IsList s, IsList t, Distributor p) =>
SepBy (p () ()) -> p (Item s) (Item t) -> p s t
several (SepBy p () ()
beg p () ()
end p () ()
sep) p (Item s) (Item t)
p = (s -> [Item s]) -> ([Item t] -> t) -> Iso s t [Item s] [Item t]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso s -> [Item s]
forall l. IsList l => l -> [Item l]
toList [Item t] -> t
forall l. IsList l => [Item l] -> l
fromList (Exchange
   (Either () (Item s, [Item s]))
   (Either () (Item t, [Item t]))
   [Item s]
   (Identity [Item t])
 -> Exchange
      (Either () (Item s, [Item s]))
      (Either () (Item t, [Item t]))
      s
      (Identity t))
-> (Exchange
      (Either () (Item s, [Item s]))
      (Either () (Item t, [Item t]))
      (Either () (Item s, [Item s]))
      (Identity (Either () (Item t, [Item t])))
    -> Exchange
         (Either () (Item s, [Item s]))
         (Either () (Item t, [Item t]))
         [Item s]
         (Identity [Item t]))
-> Exchange
     (Either () (Item s, [Item s]))
     (Either () (Item t, [Item t]))
     (Either () (Item s, [Item s]))
     (Identity (Either () (Item t, [Item t])))
-> Exchange
     (Either () (Item s, [Item s]))
     (Either () (Item t, [Item t]))
     s
     (Identity t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Exchange
  (Either () (Item s, [Item s]))
  (Either () (Item t, [Item t]))
  (Either () (Item s, [Item s]))
  (Identity (Either () (Item t, [Item t])))
-> Exchange
     (Either () (Item s, [Item s]))
     (Either () (Item t, [Item t]))
     [Item s]
     (Identity [Item t])
forall s a t b.
(Cons s s a a, AsEmpty t, Cons t t b b) =>
Iso s t (Either () (a, s)) (Either () (b, t))
Iso
  [Item s]
  [Item t]
  (Either () (Item s, [Item s]))
  (Either () (Item t, [Item t]))
eotList (Exchange
   (Either () (Item s, [Item s]))
   (Either () (Item t, [Item t]))
   (Either () (Item s, [Item s]))
   (Identity (Either () (Item t, [Item t])))
 -> Exchange
      (Either () (Item s, [Item s]))
      (Either () (Item t, [Item t]))
      s
      (Identity t))
-> p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
-> p s t
forall (p :: * -> * -> *) s t a b.
Profunctor p =>
AnIso s t a b -> p a b -> p s t
>~
  p () ()
beg p () ()
-> p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
-> p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* (p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p () ()
-> p (Item s, [Item s]) (Item t, [Item t])
-> p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
forall a b c d. p a b -> p c d -> p (Either a c) (Either b d)
forall (p :: * -> * -> *) a b c d.
Distributor p =>
p a b -> p c d -> p (Either a c) (Either b d)
>+< p (Item s) (Item t)
p p (Item s) (Item t)
-> p [Item s] [Item t] -> p (Item s, [Item s]) (Item t, [Item t])
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p (Item s) (Item t) -> p [Item s] [Item t]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p () ()
sep p () () -> p (Item s) (Item t) -> p (Item s) (Item t)
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p (Item s) (Item t)
p)) p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
-> p () ()
-> p (Either () (Item s, [Item s])) (Either () (Item t, [Item t]))
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end

{- |
prop> several1 noSep p = someP p
-}
several1
  :: (IsList s, IsList t, Distributor p, Choice p)
  => SepBy (p () ()) -> p (Item s) (Item t) -> p s t
several1 :: forall s t (p :: * -> * -> *).
(IsList s, IsList t, Distributor p, Choice p) =>
SepBy (p () ()) -> p (Item s) (Item t) -> p s t
several1 (SepBy p () ()
beg p () ()
end p () ()
sep) p (Item s) (Item t)
p = (s -> [Item s]) -> ([Item t] -> t) -> Iso s t [Item s] [Item t]
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso s -> [Item s]
forall l. IsList l => l -> [Item l]
toList [Item t] -> t
forall l. IsList l => [Item l] -> l
fromList (Market
   (Item s, [Item s]) (Item t, [Item t]) [Item s] (Identity [Item t])
 -> Market (Item s, [Item s]) (Item t, [Item t]) s (Identity t))
-> (Market
      (Item s, [Item s])
      (Item t, [Item t])
      (Item s, [Item s])
      (Identity (Item t, [Item t]))
    -> Market
         (Item s, [Item s]) (Item t, [Item t]) [Item s] (Identity [Item t]))
-> Market
     (Item s, [Item s])
     (Item t, [Item t])
     (Item s, [Item s])
     (Identity (Item t, [Item t]))
-> Market (Item s, [Item s]) (Item t, [Item t]) s (Identity t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Market
  (Item s, [Item s])
  (Item t, [Item t])
  (Item s, [Item s])
  (Identity (Item t, [Item t]))
-> Market
     (Item s, [Item s]) (Item t, [Item t]) [Item s] (Identity [Item t])
forall s t a b. Cons s t a b => Prism s t (a, s) (b, t)
Prism [Item s] [Item t] (Item s, [Item s]) (Item t, [Item t])
_Cons (Market
   (Item s, [Item s])
   (Item t, [Item t])
   (Item s, [Item s])
   (Identity (Item t, [Item t]))
 -> Market (Item s, [Item s]) (Item t, [Item t]) s (Identity t))
-> p (Item s, [Item s]) (Item t, [Item t]) -> p s t
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>?
  p () ()
beg p () ()
-> p (Item s, [Item s]) (Item t, [Item t])
-> p (Item s, [Item s]) (Item t, [Item t])
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* (p (Item s) (Item t)
p p (Item s) (Item t)
-> p [Item s] [Item t] -> p (Item s, [Item s]) (Item t, [Item t])
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p (Item s) (Item t) -> p [Item s] [Item t]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p () ()
sep p () () -> p (Item s) (Item t) -> p (Item s) (Item t)
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p (Item s) (Item t)
p)) p (Item s, [Item s]) (Item t, [Item t])
-> p () () -> p (Item s, [Item s]) (Item t, [Item t])
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end

{- | Use a nilary constructor pattern to sequence zero times, or
associate a binary constructor pattern to sequence one or more times. -}
chain
  :: Alternator p
  => (forall x. x -> Either x x) -- ^ `Left` or `Right` associate
  -> APartialIso a b (a,a) (b,b) -- ^ binary constructor pattern
  -> APrism a b () () -- ^ nilary constructor pattern
  -> SepBy (p () ()) -> p a b -> p a b
chain :: forall (p :: * -> * -> *) a b.
Alternator p =>
(forall x. x -> Either x x)
-> APartialIso a b (a, a) (b, b)
-> APrism a b () ()
-> SepBy (p () ())
-> p a b
-> p a b
chain forall x. x -> Either x x
association APartialIso a b (a, a) (b, b)
pat2 APrism a b () ()
pat0 (SepBy p () ()
beg p () ()
end p () ()
sep) p a b
p =
  p () ()
beg p () () -> p a b -> p a b
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* (APrism a b () ()
pat0 APrism a b () () -> p () () -> p a b
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p () ()
forall (p :: * -> * -> *). Monoidal p => p () ()
oneP p a b -> p a b -> p a b
forall a. p a a -> p a a -> p a a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall x. x -> Either x x)
-> APartialIso a b (a, a) (b, b)
-> SepBy (p () ())
-> p a b
-> p a b
forall (p :: * -> * -> *) a b.
(Distributor p, Choice p) =>
(forall x. x -> Either x x)
-> APartialIso a b (a, a) (b, b)
-> SepBy (p () ())
-> p a b
-> p a b
chain1 x -> Either x x
forall x. x -> Either x x
association APartialIso a b (a, a) (b, b)
pat2 (p () () -> SepBy (p () ())
forall (p :: * -> * -> *). Monoidal p => p () () -> SepBy (p () ())
sepBy p () ()
sep) p a b
p) p a b -> p () () -> p a b
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end

{- | Associate a binary constructor pattern to sequence one or more times. -}
chain1
  :: (Distributor p, Choice p)
  => (forall x. x -> Either x x) -- ^ `Left` or `Right` associate
  -> APartialIso a b (a,a) (b,b) -- ^ binary constructor pattern
  -> SepBy (p () ()) -> p a b -> p a b
chain1 :: forall (p :: * -> * -> *) a b.
(Distributor p, Choice p) =>
(forall x. x -> Either x x)
-> APartialIso a b (a, a) (b, b)
-> SepBy (p () ())
-> p a b
-> p a b
chain1 forall x. x -> Either x x
association APartialIso a b (a, a) (b, b)
pat (SepBy p () ()
beg p () ()
end p () ()
sep) = (p a b -> p a b) -> (p a b -> p a b) -> p a b -> p a b
leftOrRight p a b -> p a b
chainl1 p a b -> p a b
chainr1
  where
    leftOrRight :: (p a b -> p a b) -> (p a b -> p a b) -> p a b -> p a b
leftOrRight p a b -> p a b
a p a b -> p a b
b = case () -> Either () ()
forall x. x -> Either x x
association () of Left ()
_ -> p a b -> p a b
a; Right ()
_ -> p a b -> p a b
b
    chainl1 :: p a b -> p a b
chainl1 p a b
p = APartialIso a b (a, a) (b, b) -> Prism a b (a, [a]) (b, [b])
forall t s a b d c.
(AsEmpty t, Cons s t a b) =>
APartialIso d c (d, b) (c, a) -> Prism d c (d, t) (c, s)
difoldl APartialIso a b (a, a) (b, b)
pat (Market (a, [a]) (b, [b]) (a, [a]) (Identity (b, [b]))
 -> Market (a, [a]) (b, [b]) a (Identity b))
-> p (a, [a]) (b, [b]) -> p a b
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p () ()
beg p () () -> p a b -> p a b
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p a b
p p a b -> p [a] [b] -> p (a, [a]) (b, [b])
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p () ()
sep p () () -> p a b -> p a b
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p a b
p) p [a] [b] -> p () () -> p [a] [b]
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end
    chainr1 :: p a b -> p a b
chainr1 p a b
p = APartialIso a b (a, a) (b, b) -> Prism a b ([a], a) ([b], b)
forall t s a b d c.
(AsEmpty t, Cons s t a b) =>
APartialIso d c (b, d) (a, c) -> Prism d c (t, d) (s, c)
difoldr APartialIso a b (a, a) (b, b)
pat (Market ([a], a) ([b], b) ([a], a) (Identity ([b], b))
 -> Market ([a], a) ([b], b) a (Identity b))
-> p ([a], a) ([b], b) -> p a b
forall (p :: * -> * -> *) s t a b.
Choice p =>
APrism s t a b -> p a b -> p s t
>? p () ()
beg p () () -> p [a] [b] -> p [a] [b]
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p a b -> p [a] [b]
forall a b. p a b -> p [a] [b]
forall (p :: * -> * -> *) a b. Distributor p => p a b -> p [a] [b]
manyP (p a b
p p a b -> p () () -> p a b
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
sep) p [a] [b] -> p a b -> p ([a], a) ([b], b)
forall (p :: * -> * -> *) a b c d.
Monoidal p =>
p a b -> p c d -> p (a, c) (b, d)
>*< p a b
p p a b -> p () () -> p a b
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end

{- | `intercalateP` adds a `SepBy` to `replicateP`. -}
intercalateP
  :: (Monoidal p, Choice p, AsEmpty s, AsEmpty t, Cons s t a b)
  => Int -> SepBy (p () ()) -> p a b -> p s t
intercalateP :: forall (p :: * -> * -> *) s t a b.
(Monoidal p, Choice p, AsEmpty s, AsEmpty t, Cons s t a b) =>
Int -> SepBy (p () ()) -> p a b -> p s t
intercalateP Int
n (SepBy p () ()
beg p () ()
end p () ()
_) p a b
_ | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 =
  p () ()
beg p () () -> p s t -> p s t
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* (s -> t) -> p t t -> p s t
forall a b c. (a -> b) -> p b c -> p a c
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap (t -> s -> t
forall a b. a -> b -> a
const t
forall s. AsEmpty s => s
Empty) p t t
forall s (p :: * -> * -> *).
(AsEmpty s, Monoidal p, Choice p) =>
p s s
asEmpty p s t -> p () () -> p s t
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end
intercalateP Int
n (SepBy p () ()
beg p () ()
end p () ()
comma) p a b
p =
  p () ()
beg p () () -> p a b -> p a b
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p a b
p p a b -> p s t -> p s t
forall s t a b (p :: * -> * -> *).
(Cons s t a b, Monoidal p, Choice p) =>
p a b -> p s t -> p s t
>:< Int -> p a b -> p s t
forall (p :: * -> * -> *) s t a b.
(Monoidal p, Choice p, AsEmpty s, AsEmpty t, Cons s t a b) =>
Int -> p a b -> p s t
replicateP (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) (p () ()
comma p () () -> p a b -> p a b
forall (p :: * -> * -> *) c a b.
Monoidal p =>
p () c -> p a b -> p a b
>* p a b
p) p s t -> p () () -> p s t
forall (p :: * -> * -> *) a b c.
Monoidal p =>
p a b -> p () c -> p a b
*< p () ()
end