{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE RoleAnnotations #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}

-----------------------------------------------------------------------------

-- |

-- Module      :  Control.Lens.Internal.Bazaar

-- Copyright   :  (C) 2012-2016 Edward Kmett

-- License     :  BSD-style (see the file LICENSE)

-- Maintainer  :  Edward Kmett <ekmett@gmail.com>

-- Stability   :  experimental

-- Portability :  non-portable

--

----------------------------------------------------------------------------

module Control.Lens.Internal.Bazaar
  ( Bizarre(..)
  , Bazaar(..), Bazaar'
  , BazaarT(..), BazaarT'
  , Bizarre1(..)
  , Bazaar1(..), Bazaar1'
  , BazaarT1(..), BazaarT1'
  ) where

import Prelude ()

import Control.Arrow as Arrow
import qualified Control.Category as C
import Control.Comonad
import Control.Lens.Internal.Prelude
import Control.Lens.Internal.Context
import Control.Lens.Internal.Indexed
import Data.Functor.Apply
import Data.Kind
import Data.Profunctor.Rep

------------------------------------------------------------------------------

-- Bizarre

------------------------------------------------------------------------------


-- | This class is used to run the various 'Bazaar' variants used in this

-- library.

class Profunctor p => Bizarre p w | w -> p where
  bazaar :: Applicative f => p a (f b) -> w a b t -> f t

------------------------------------------------------------------------------

-- Bazaar

------------------------------------------------------------------------------


-- | This is used to characterize a 'Control.Lens.Traversal.Traversal'.

--

-- a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed 'FunList'.

--

-- <http://twanvl.nl/blog/haskell/non-regular1>

--

-- A 'Bazaar' is like a 'Control.Lens.Traversal.Traversal' that has already been applied to some structure.

--

-- Where a @'Context' a b t@ holds an @a@ and a function from @b@ to

-- @t@, a @'Bazaar' a b t@ holds @N@ @a@s and a function from @N@

-- @b@s to @t@, (where @N@ might be infinite).

--

-- Mnemonically, a 'Bazaar' holds many stores and you can easily add more.

--

-- This is a final encoding of 'Bazaar'.

newtype Bazaar p a b t = Bazaar { forall (p :: * -> * -> *) a b t.
Bazaar p a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaar :: forall f. Applicative f => p a (f b) -> f t }
-- type role Bazaar representatonal nominal nominal nominal


-- | This alias is helpful when it comes to reducing repetition in type signatures.

--

-- @

-- type 'Bazaar'' p a t = 'Bazaar' p a a t

-- @

type Bazaar' p a = Bazaar p a a

instance IndexedFunctor (Bazaar p) where
  ifmap :: forall s t a b. (s -> t) -> Bazaar p a b s -> Bazaar p a b t
ifmap s -> t
f (Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f s
k) = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> t
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Applicative f => p a (f b) -> f s
k)
  {-# INLINE ifmap #-}

instance Conjoined p => IndexedComonad (Bazaar p) where
  iextract :: forall a t. Bazaar p a a t -> t
iextract (Bazaar forall (f :: * -> *). Applicative f => p a (f a) -> f t
m) = forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => p a (f a) -> f t
m (forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a. a -> Identity a
Identity)
  {-# INLINE iextract #-}
  iduplicate :: forall a c t b. Bazaar p a c t -> Bazaar p a b (Bazaar p b c t)
iduplicate (Bazaar forall (f :: * -> *). Applicative f => p a (f c) -> f t
m) = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => p a (f c) -> f t
m (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Conjoined p, Functor f) =>
p a b -> p (f a) (f b)
distrib forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
C.. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell)
  {-# INLINE iduplicate #-}

instance Corepresentable p => Sellable p (Bazaar p) where
  sell :: forall a b. p a (Bazaar p a b b)
sell = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p a
w -> forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) d c.
Representable p =>
(d -> Rep p c) -> p d c
tabulate forall a b. (a -> b) -> a -> b
$ \p a (f b)
k -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
k Corep p a
w)
  {-# INLINE sell #-}

instance Profunctor p => Bizarre p (Bazaar p) where
  bazaar :: forall (f :: * -> *) a b t.
Applicative f =>
p a (f b) -> Bazaar p a b t -> f t
bazaar p a (f b)
g (Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f t
f) = forall (f :: * -> *). Applicative f => p a (f b) -> f t
f p a (f b)
g
  {-# INLINE bazaar #-}

instance Functor (Bazaar p a b) where
  fmap :: forall a b. (a -> b) -> Bazaar p a b a -> Bazaar p a b b
fmap = forall (w :: * -> * -> * -> *) s t a b.
IndexedFunctor w =>
(s -> t) -> w a b s -> w a b t
ifmap
  {-# INLINE fmap #-}
  a
x <$ :: forall a b. a -> Bazaar p a b b -> Bazaar p a b a
<$ Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f b
k = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar ( (a
x forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Applicative f => p a (f b) -> f b
k )
  {-# INLINE (<$) #-}

instance Apply (Bazaar p a b) where
  <.> :: forall a b.
Bazaar p a b (a -> b) -> Bazaar p a b a -> Bazaar p a b b
(<.>) = forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>)
  {-# INLINE (<.>) #-}
  .> :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b b
(.>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
  {-# INLINE (.>) #-}
  <. :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b a
(<.) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
(<*)
  {-# INLINE (<.) #-}

instance Applicative (Bazaar p a b) where
  pure :: forall a. a -> Bazaar p a b a
pure a
a = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ \p a (f b)
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
  {-# INLINE pure #-}
  Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f (a -> b)
mf <*> :: forall a b.
Bazaar p a b (a -> b) -> Bazaar p a b a -> Bazaar p a b b
<*> Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f a
ma = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f (a -> b)
mf p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *). Applicative f => p a (f b) -> f a
ma p a (f b)
pafb
  {-# INLINE (<*>) #-}
#if MIN_VERSION_base(4,10,0)
  liftA2 :: forall a b c.
(a -> b -> c) -> Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b c
liftA2 a -> b -> c
f (Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx) (Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f b
my) = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ \p a (f b)
pafb -> forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> c
f (forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx p a (f b)
pafb) (forall (f :: * -> *). Applicative f => p a (f b) -> f b
my p a (f b)
pafb)
  {-# INLINE liftA2 #-}
#endif
  Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx *> :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b b
*> Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f b
my = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ \p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (f :: * -> *). Applicative f => p a (f b) -> f b
my p a (f b)
pafb
  {-# INLINE (*>) #-}
  Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx <* :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b a
<* Bazaar forall (f :: * -> *). Applicative f => p a (f b) -> f b
my = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> Bazaar p a b t
Bazaar forall a b. (a -> b) -> a -> b
$ \p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (f :: * -> *). Applicative f => p a (f b) -> f b
my p a (f b)
pafb
  {-# INLINE (<*) #-}

instance (a ~ b, Conjoined p) => Comonad (Bazaar p a b) where
  extract :: forall a. Bazaar p a b a -> a
extract = forall (w :: * -> * -> * -> *) a t.
IndexedComonad w =>
w a a t -> t
iextract
  {-# INLINE extract #-}
  duplicate :: forall a. Bazaar p a b a -> Bazaar p a b (Bazaar p a b a)
duplicate = forall (w :: * -> * -> * -> *) a c t b.
IndexedComonad w =>
w a c t -> w a b (w b c t)
iduplicate
  {-# INLINE duplicate #-}

instance (a ~ b, Conjoined p) => ComonadApply (Bazaar p a b) where
  <@> :: forall a b.
Bazaar p a b (a -> b) -> Bazaar p a b a -> Bazaar p a b b
(<@>) = forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>)
  {-# INLINE (<@>) #-}
  @> :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b b
(@>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
  {-# INLINE (@>) #-}
  <@ :: forall a b. Bazaar p a b a -> Bazaar p a b b -> Bazaar p a b a
(<@) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
(<*)
  {-# INLINE (<@) #-}

------------------------------------------------------------------------------

-- BazaarT

------------------------------------------------------------------------------


-- | 'BazaarT' is like 'Bazaar', except that it provides a questionable 'Contravariant' instance

-- To protect this instance it relies on the soundness of another 'Contravariant' type, and usage conventions.

--

-- For example. This lets us write a suitably polymorphic and lazy 'Control.Lens.Traversal.taking', but there

-- must be a better way!

newtype BazaarT p (g :: Type -> Type) a b t = BazaarT { forall (p :: * -> * -> *) (g :: * -> *) a b t.
BazaarT p g a b t
-> forall (f :: * -> *). Applicative f => p a (f b) -> f t
runBazaarT :: forall f. Applicative f => p a (f b) -> f t }
type role BazaarT representational nominal nominal nominal nominal

-- | This alias is helpful when it comes to reducing repetition in type signatures.

--

-- @

-- type 'BazaarT'' p g a t = 'BazaarT' p g a a t

-- @

type BazaarT' p g a = BazaarT p g a a

instance IndexedFunctor (BazaarT p g) where
  ifmap :: forall s t a b. (s -> t) -> BazaarT p g a b s -> BazaarT p g a b t
ifmap s -> t
f (BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f s
k) = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> t
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Applicative f => p a (f b) -> f s
k)
  {-# INLINE ifmap #-}

instance Conjoined p => IndexedComonad (BazaarT p g) where
  iextract :: forall a t. BazaarT p g a a t -> t
iextract (BazaarT forall (f :: * -> *). Applicative f => p a (f a) -> f t
m) = forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => p a (f a) -> f t
m (forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a. a -> Identity a
Identity)
  {-# INLINE iextract #-}
  iduplicate :: forall a c t b.
BazaarT p g a c t -> BazaarT p g a b (BazaarT p g b c t)
iduplicate (BazaarT forall (f :: * -> *). Applicative f => p a (f c) -> f t
m) = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Applicative f => p a (f c) -> f t
m (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Conjoined p, Functor f) =>
p a b -> p (f a) (f b)
distrib forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
C.. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell)
  {-# INLINE iduplicate #-}

instance Corepresentable p => Sellable p (BazaarT p g) where
  sell :: forall a b. p a (BazaarT p g a b b)
sell = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p a
w -> forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
`cosieve` Corep p a
w)
  {-# INLINE sell #-}

instance Profunctor p => Bizarre p (BazaarT p g) where
  bazaar :: forall (f :: * -> *) a b t.
Applicative f =>
p a (f b) -> BazaarT p g a b t -> f t
bazaar p a (f b)
g (BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f t
f) = forall (f :: * -> *). Applicative f => p a (f b) -> f t
f p a (f b)
g
  {-# INLINE bazaar #-}

instance Functor (BazaarT p g a b) where
  fmap :: forall a b. (a -> b) -> BazaarT p g a b a -> BazaarT p g a b b
fmap = forall (w :: * -> * -> * -> *) s t a b.
IndexedFunctor w =>
(s -> t) -> w a b s -> w a b t
ifmap
  {-# INLINE fmap #-}
  a
x <$ :: forall a b. a -> BazaarT p g a b b -> BazaarT p g a b a
<$ BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f b
k = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT ( (a
x forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Applicative f => p a (f b) -> f b
k )
  {-# INLINE (<$) #-}

instance Apply (BazaarT p g a b) where
  <.> :: forall a b.
BazaarT p g a b (a -> b) -> BazaarT p g a b a -> BazaarT p g a b b
(<.>) = forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>)
  {-# INLINE (<.>) #-}
  .> :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b b
(.>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
  {-# INLINE (.>) #-}
  <. :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b a
(<.) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
(<*)
  {-# INLINE (<.) #-}

instance Applicative (BazaarT p g a b) where
  pure :: forall a. a -> BazaarT p g a b a
pure a
a = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) d c.
Representable p =>
(d -> Rep p c) -> p d c
tabulate forall a b. (a -> b) -> a -> b
$ \p a (f b)
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a)
  {-# INLINE pure #-}
  BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f (a -> b)
mf <*> :: forall a b.
BazaarT p g a b (a -> b) -> BazaarT p g a b a -> BazaarT p g a b b
<*> BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f a
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f (a -> b)
mf p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (f :: * -> *). Applicative f => p a (f b) -> f a
ma p a (f b)
pafb
  {-# INLINE (<*>) #-}
#if MIN_VERSION_base(4,10,0)
  liftA2 :: forall a b c.
(a -> b -> c)
-> BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b c
liftA2 a -> b -> c
f (BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx) (BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f b
my) = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \p a (f b)
pafb -> forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 a -> b -> c
f (forall (f :: * -> *). Applicative f => p a (f b) -> f a
mx p a (f b)
pafb) (forall (f :: * -> *). Applicative f => p a (f b) -> f b
my p a (f b)
pafb)
  {-# INLINE liftA2 #-}
#endif
  BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f a
mf *> :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b b
*> BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (f :: * -> *). Applicative f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (*>) #-}
  BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f a
mf <* :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b a
<* BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Applicative f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (f :: * -> *). Applicative f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (<*) #-}

instance (a ~ b, Conjoined p) => Comonad (BazaarT p g a b) where
  extract :: forall a. BazaarT p g a b a -> a
extract = forall (w :: * -> * -> * -> *) a t.
IndexedComonad w =>
w a a t -> t
iextract
  {-# INLINE extract #-}
  duplicate :: forall a. BazaarT p g a b a -> BazaarT p g a b (BazaarT p g a b a)
duplicate = forall (w :: * -> * -> * -> *) a c t b.
IndexedComonad w =>
w a c t -> w a b (w b c t)
iduplicate
  {-# INLINE duplicate #-}

instance (a ~ b, Conjoined p) => ComonadApply (BazaarT p g a b) where
  <@> :: forall a b.
BazaarT p g a b (a -> b) -> BazaarT p g a b a -> BazaarT p g a b b
(<@>) = forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>)
  {-# INLINE (<@>) #-}
  @> :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b b
(@>) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
  {-# INLINE (@>) #-}
  <@ :: forall a b.
BazaarT p g a b a -> BazaarT p g a b b -> BazaarT p g a b a
(<@) = forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
(<*)
  {-# INLINE (<@) #-}

instance (Profunctor p, Contravariant g) => Contravariant (BazaarT p g a b) where
  contramap :: forall a' a. (a' -> a) -> BazaarT p g a b a -> BazaarT p g a b a'
contramap a' -> a
_ = forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$) (forall a. HasCallStack => [Char] -> a
error [Char]
"contramap: BazaarT")
  {-# INLINE contramap #-}

instance Contravariant g => Semigroup (BazaarT p g a b t) where
  BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f t
a <> :: BazaarT p g a b t -> BazaarT p g a b t -> BazaarT p g a b t
<> BazaarT forall (f :: * -> *). Applicative f => p a (f b) -> f t
b = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \p a (f b)
f -> forall (f :: * -> *). Applicative f => p a (f b) -> f t
a p a (f b)
f forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (f :: * -> *). Applicative f => p a (f b) -> f t
b p a (f b)
f
  {-# INLINE (<>) #-}

instance Contravariant g => Monoid (BazaarT p g a b t) where
  mempty :: BazaarT p g a b t
mempty = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Applicative f => p a (f b) -> f t)
-> BazaarT p g a b t
BazaarT forall a b. (a -> b) -> a -> b
$ \p a (f b)
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. HasCallStack => [Char] -> a
error [Char]
"mempty: BazaarT")
  {-# INLINE mempty #-}
#if !(MIN_VERSION_base(4,11,0))
  BazaarT a `mappend` BazaarT b = BazaarT $ \f -> a f <* b f
  {-# INLINE mappend #-}
#endif


------------------------------------------------------------------------------

-- Bizarre1

------------------------------------------------------------------------------


class Profunctor p => Bizarre1 p w | w -> p where
  bazaar1 :: Apply f => p a (f b) -> w a b t -> f t

------------------------------------------------------------------------------

-- Bazaar1

------------------------------------------------------------------------------


-- | This is used to characterize a 'Control.Lens.Traversal.Traversal'.

--

-- a.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed 'FunList'.

--

-- <http://twanvl.nl/blog/haskell/non-regular1>

--

-- A 'Bazaar1' is like a 'Control.Lens.Traversal.Traversal' that has already been applied to some structure.

--

-- Where a @'Context' a b t@ holds an @a@ and a function from @b@ to

-- @t@, a @'Bazaar1' a b t@ holds @N@ @a@s and a function from @N@

-- @b@s to @t@, (where @N@ might be infinite).

--

-- Mnemonically, a 'Bazaar1' holds many stores and you can easily add more.

--

-- This is a final encoding of 'Bazaar1'.

newtype Bazaar1 p a b t = Bazaar1 { forall (p :: * -> * -> *) a b t.
Bazaar1 p a b t
-> forall (f :: * -> *). Apply f => p a (f b) -> f t
runBazaar1 :: forall f. Apply f => p a (f b) -> f t }
-- type role Bazaar1 representatonal nominal nominal nominal


-- | This alias is helpful when it comes to reducing repetition in type signatures.

--

-- @

-- type 'Bazaar1'' p a t = 'Bazaar1' p a a t

-- @

type Bazaar1' p a = Bazaar1 p a a

instance IndexedFunctor (Bazaar1 p) where
  ifmap :: forall s t a b. (s -> t) -> Bazaar1 p a b s -> Bazaar1 p a b t
ifmap s -> t
f (Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f s
k) = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> t
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Apply f => p a (f b) -> f s
k)
  {-# INLINE ifmap #-}

instance Conjoined p => IndexedComonad (Bazaar1 p) where
  iextract :: forall a t. Bazaar1 p a a t -> t
iextract (Bazaar1 forall (f :: * -> *). Apply f => p a (f a) -> f t
m) = forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Apply f => p a (f a) -> f t
m (forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a. a -> Identity a
Identity)
  {-# INLINE iextract #-}
  iduplicate :: forall a c t b. Bazaar1 p a c t -> Bazaar1 p a b (Bazaar1 p b c t)
iduplicate (Bazaar1 forall (f :: * -> *). Apply f => p a (f c) -> f t
m) = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Apply f => p a (f c) -> f t
m (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Conjoined p, Functor f) =>
p a b -> p (f a) (f b)
distrib forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
C.. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell)
  {-# INLINE iduplicate #-}

instance Corepresentable p => Sellable p (Bazaar1 p) where
  sell :: forall a b. p a (Bazaar1 p a b b)
sell = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p a
w -> forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 forall a b. (a -> b) -> a -> b
$ forall (p :: * -> * -> *) d c.
Representable p =>
(d -> Rep p c) -> p d c
tabulate forall a b. (a -> b) -> a -> b
$ \p a (f b)
k -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
cosieve p a (f b)
k Corep p a
w)
  {-# INLINE sell #-}

instance Profunctor p => Bizarre1 p (Bazaar1 p) where
  bazaar1 :: forall (f :: * -> *) a b t.
Apply f =>
p a (f b) -> Bazaar1 p a b t -> f t
bazaar1 p a (f b)
g (Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f t
f) = forall (f :: * -> *). Apply f => p a (f b) -> f t
f p a (f b)
g
  {-# INLINE bazaar1 #-}

instance Functor (Bazaar1 p a b) where
  fmap :: forall a b. (a -> b) -> Bazaar1 p a b a -> Bazaar1 p a b b
fmap = forall (w :: * -> * -> * -> *) s t a b.
IndexedFunctor w =>
(s -> t) -> w a b s -> w a b t
ifmap
  {-# INLINE fmap #-}
  a
x <$ :: forall a b. a -> Bazaar1 p a b b -> Bazaar1 p a b a
<$ Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f b
k = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 ((a
x forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Apply f => p a (f b) -> f b
k)
  {-# INLINE (<$) #-}

instance Apply (Bazaar1 p a b) where
  Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f (a -> b)
mf <.> :: forall a b.
Bazaar1 p a b (a -> b) -> Bazaar1 p a b a -> Bazaar1 p a b b
<.> Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f a
ma = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f (a -> b)
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (f :: * -> *). Apply f => p a (f b) -> f a
ma p a (f b)
pafb
  {-# INLINE (<.>) #-}
  Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f a
mf .> :: forall a b. Bazaar1 p a b a -> Bazaar1 p a b b -> Bazaar1 p a b b
.> Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f a -> f b -> f b
.> forall (f :: * -> *). Apply f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (.>) #-}
  Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f a
mf <. :: forall a b. Bazaar1 p a b a -> Bazaar1 p a b b -> Bazaar1 p a b a
<. Bazaar1 forall (f :: * -> *). Apply f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> Bazaar1 p a b t
Bazaar1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f a -> f b -> f a
<. forall (f :: * -> *). Apply f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (<.) #-}

instance (a ~ b, Conjoined p) => Comonad (Bazaar1 p a b) where
  extract :: forall a. Bazaar1 p a b a -> a
extract = forall (w :: * -> * -> * -> *) a t.
IndexedComonad w =>
w a a t -> t
iextract
  {-# INLINE extract #-}
  duplicate :: forall a. Bazaar1 p a b a -> Bazaar1 p a b (Bazaar1 p a b a)
duplicate = forall (w :: * -> * -> * -> *) a c t b.
IndexedComonad w =>
w a c t -> w a b (w b c t)
iduplicate
  {-# INLINE duplicate #-}

instance (a ~ b, Conjoined p) => ComonadApply (Bazaar1 p a b) where
  <@> :: forall a b.
Bazaar1 p a b (a -> b) -> Bazaar1 p a b a -> Bazaar1 p a b b
(<@>) = forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
(<.>)
  {-# INLINE (<@>) #-}
  @> :: forall a b. Bazaar1 p a b a -> Bazaar1 p a b b -> Bazaar1 p a b b
(@>) = forall (f :: * -> *) a b. Apply f => f a -> f b -> f b
(.>)
  {-# INLINE (@>) #-}
  <@ :: forall a b. Bazaar1 p a b a -> Bazaar1 p a b b -> Bazaar1 p a b a
(<@) = forall (f :: * -> *) a b. Apply f => f a -> f b -> f a
(<.)
  {-# INLINE (<@) #-}

------------------------------------------------------------------------------

-- BazaarT1

------------------------------------------------------------------------------


-- | 'BazaarT1' is like 'Bazaar1', except that it provides a questionable 'Contravariant' instance

-- To protect this instance it relies on the soundness of another 'Contravariant' type, and usage conventions.

--

-- For example. This lets us write a suitably polymorphic and lazy 'Control.Lens.Traversal.taking', but there

-- must be a better way!

newtype BazaarT1 p (g :: Type -> Type) a b t = BazaarT1 { forall (p :: * -> * -> *) (g :: * -> *) a b t.
BazaarT1 p g a b t
-> forall (f :: * -> *). Apply f => p a (f b) -> f t
runBazaarT1 :: forall f. Apply f => p a (f b) -> f t }
type role BazaarT1 representational nominal nominal nominal nominal

-- | This alias is helpful when it comes to reducing repetition in type signatures.

--

-- @

-- type 'BazaarT1'' p g a t = 'BazaarT1' p g a a t

-- @

type BazaarT1' p g a = BazaarT1 p g a a

instance IndexedFunctor (BazaarT1 p g) where
  ifmap :: forall s t a b.
(s -> t) -> BazaarT1 p g a b s -> BazaarT1 p g a b t
ifmap s -> t
f (BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f s
k) = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap s -> t
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Apply f => p a (f b) -> f s
k)
  {-# INLINE ifmap #-}

instance Conjoined p => IndexedComonad (BazaarT1 p g) where
  iextract :: forall a t. BazaarT1 p g a a t -> t
iextract (BazaarT1 forall (f :: * -> *). Apply f => p a (f a) -> f t
m) = forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Apply f => p a (f a) -> f t
m (forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall a. a -> Identity a
Identity)
  {-# INLINE iextract #-}
  iduplicate :: forall a c t b.
BazaarT1 p g a c t -> BazaarT1 p g a b (BazaarT1 p g b c t)
iduplicate (BazaarT1 forall (f :: * -> *). Apply f => p a (f c) -> f t
m) = forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *). Apply f => p a (f c) -> f t
m (forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (p :: * -> * -> *) a b c (q :: * -> * -> *).
(Profunctor p, Coercible c b) =>
q b c -> p a b -> p a c
#. forall (p :: * -> * -> *) (f :: * -> *) a b.
(Conjoined p, Functor f) =>
p a b -> p (f a) (f b)
distrib forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
C.. forall (p :: * -> * -> *) (w :: * -> * -> * -> *) a b.
Sellable p w =>
p a (w a b b)
sell)
  {-# INLINE iduplicate #-}

instance Corepresentable p => Sellable p (BazaarT1 p g) where
  sell :: forall a b. p a (BazaarT1 p g a b b)
sell = forall (p :: * -> * -> *) d c.
Corepresentable p =>
(Corep p d -> c) -> p d c
cotabulate forall a b. (a -> b) -> a -> b
$ \ Corep p a
w -> forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 (forall (p :: * -> * -> *) (f :: * -> *) a b.
Cosieve p f =>
p a b -> f a -> b
`cosieve` Corep p a
w)
  {-# INLINE sell #-}

instance Profunctor p => Bizarre1 p (BazaarT1 p g) where
  bazaar1 :: forall (f :: * -> *) a b t.
Apply f =>
p a (f b) -> BazaarT1 p g a b t -> f t
bazaar1 p a (f b)
g (BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f t
f) = forall (f :: * -> *). Apply f => p a (f b) -> f t
f p a (f b)
g
  {-# INLINE bazaar1 #-}

instance Functor (BazaarT1 p g a b) where
  fmap :: forall a b. (a -> b) -> BazaarT1 p g a b a -> BazaarT1 p g a b b
fmap = forall (w :: * -> * -> * -> *) s t a b.
IndexedFunctor w =>
(s -> t) -> w a b s -> w a b t
ifmap
  {-# INLINE fmap #-}
  a
x <$ :: forall a b. a -> BazaarT1 p g a b b -> BazaarT1 p g a b a
<$ BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f b
k = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 ((a
x forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Apply f => p a (f b) -> f b
k)
  {-# INLINE (<$) #-}

instance Apply (BazaarT1 p g a b) where
  BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f (a -> b)
mf <.> :: forall a b.
BazaarT1 p g a b (a -> b)
-> BazaarT1 p g a b a -> BazaarT1 p g a b b
<.> BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f a
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f (a -> b)
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall (f :: * -> *). Apply f => p a (f b) -> f a
ma p a (f b)
pafb
  {-# INLINE (<.>) #-}
  BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f a
mf .> :: forall a b.
BazaarT1 p g a b a -> BazaarT1 p g a b b -> BazaarT1 p g a b b
.> BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f a -> f b -> f b
.> forall (f :: * -> *). Apply f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (.>) #-}
  BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f a
mf <. :: forall a b.
BazaarT1 p g a b a -> BazaarT1 p g a b b -> BazaarT1 p g a b a
<. BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f b
ma = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 forall a b. (a -> b) -> a -> b
$ \ p a (f b)
pafb -> forall (f :: * -> *). Apply f => p a (f b) -> f a
mf p a (f b)
pafb forall (f :: * -> *) a b. Apply f => f a -> f b -> f a
<. forall (f :: * -> *). Apply f => p a (f b) -> f b
ma p a (f b)
pafb
  {-# INLINE (<.) #-}

instance (a ~ b, Conjoined p) => Comonad (BazaarT1 p g a b) where
  extract :: forall a. BazaarT1 p g a b a -> a
extract = forall (w :: * -> * -> * -> *) a t.
IndexedComonad w =>
w a a t -> t
iextract
  {-# INLINE extract #-}
  duplicate :: forall a.
BazaarT1 p g a b a -> BazaarT1 p g a b (BazaarT1 p g a b a)
duplicate = forall (w :: * -> * -> * -> *) a c t b.
IndexedComonad w =>
w a c t -> w a b (w b c t)
iduplicate
  {-# INLINE duplicate #-}

instance (a ~ b, Conjoined p) => ComonadApply (BazaarT1 p g a b) where
  <@> :: forall a b.
BazaarT1 p g a b (a -> b)
-> BazaarT1 p g a b a -> BazaarT1 p g a b b
(<@>) = forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
(<.>)
  {-# INLINE (<@>) #-}
  @> :: forall a b.
BazaarT1 p g a b a -> BazaarT1 p g a b b -> BazaarT1 p g a b b
(@>) = forall (f :: * -> *) a b. Apply f => f a -> f b -> f b
(.>)
  {-# INLINE (@>) #-}
  <@ :: forall a b.
BazaarT1 p g a b a -> BazaarT1 p g a b b -> BazaarT1 p g a b a
(<@) = forall (f :: * -> *) a b. Apply f => f a -> f b -> f a
(<.)
  {-# INLINE (<@) #-}

instance (Profunctor p, Contravariant g) => Contravariant (BazaarT1 p g a b) where
  contramap :: forall a' a. (a' -> a) -> BazaarT1 p g a b a -> BazaarT1 p g a b a'
contramap a' -> a
_ = forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$) (forall a. HasCallStack => [Char] -> a
error [Char]
"contramap: BazaarT1")
  {-# INLINE contramap #-}

instance Contravariant g => Semigroup (BazaarT1 p g a b t) where
  BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f t
a <> :: BazaarT1 p g a b t -> BazaarT1 p g a b t -> BazaarT1 p g a b t
<> BazaarT1 forall (f :: * -> *). Apply f => p a (f b) -> f t
b = forall (p :: * -> * -> *) (g :: * -> *) a b t.
(forall (f :: * -> *). Apply f => p a (f b) -> f t)
-> BazaarT1 p g a b t
BazaarT1 forall a b. (a -> b) -> a -> b
$ \p a (f b)
f -> forall (f :: * -> *). Apply f => p a (f b) -> f t
a p a (f b)
f forall (f :: * -> *) a b. Apply f => f a -> f b -> f a
<. forall (f :: * -> *). Apply f => p a (f b) -> f t
b p a (f b)
f
  {-# INLINE (<>) #-}