    {-# LANGUAGE CPP #-}
    {-# LANGUAGE RankNTypes #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    #ifdef TRUSTWORTHY
    {-# LANGUAGE Trustworthy #-}
    #endif
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Control.Lens.Action.Reified
    -- Copyright   :  (C) 2012-14 Edward Kmett
    -- License     :  BSD-style (see the file LICENSE)
    -- Maintainer  :  Edward Kmett <ekmett@gmail.com>
    -- Stability   :  experimental
    -- Portability :  non-portable
    --
    ----------------------------------------------------------------------------
    module Control.Lens.Action.Reified where

    import Control.Applicative
    import Control.Arrow
    import qualified Control.Category as Cat
    import Control.Lens hiding ((<.>))
    import Control.Monad
    import Control.Monad.Reader.Class
    import Data.Functor.Contravariant
    import Data.Functor.Bind
    import Data.Functor.Plus
    import Data.Profunctor
    #if !(MIN_VERSION_base(4,11,0))
    import Data.Semigroup
    #endif

    import Control.Lens.Action

    ------------------------------------------------------------------------------
    -- MonadicFold
    ------------------------------------------------------------------------------

    -- | Reify a 'MonadicFold' so it can be stored safely in a container.
    --
    newtype ReifiedMonadicFold m s a = MonadicFold { forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold :: MonadicFold m s a }

    instance Profunctor (ReifiedMonadicFold m) where
      dimap :: forall a b c d.
    (a -> b)
    -> (c -> d) -> ReifiedMonadicFold m b c -> ReifiedMonadicFold m a d
    dimap a -> b
    f c -> d
    g ReifiedMonadicFold m b c
    l = MonadicFold m a d -> ReifiedMonadicFold m a d
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold ((a -> b) -> (b -> f b) -> a -> f a
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to a -> b
    f ((b -> f b) -> a -> f a)
    -> ((d -> f d) -> b -> f b) -> (d -> f d) -> a -> f a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReifiedMonadicFold m b c -> MonadicFold m b c
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m b c
    l ((c -> f c) -> b -> f b)
    -> ((d -> f d) -> c -> f c) -> (d -> f d) -> b -> f b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (c -> d) -> (d -> f d) -> c -> f c
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to c -> d
    g)
      {-# INLINE dimap #-}
      rmap :: forall b c a.
    (b -> c) -> ReifiedMonadicFold m a b -> ReifiedMonadicFold m a c
    rmap b -> c
    g ReifiedMonadicFold m a b
    l = MonadicFold m a c -> ReifiedMonadicFold m a c
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (ReifiedMonadicFold m a b -> MonadicFold m a b
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m a b
    l ((b -> f b) -> a -> f a)
    -> ((c -> f c) -> b -> f b) -> (c -> f c) -> a -> f a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (b -> c) -> (c -> f c) -> b -> f b
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to b -> c
    g)
      {-# INLINE rmap #-}
      lmap :: forall a b c.
    (a -> b) -> ReifiedMonadicFold m b c -> ReifiedMonadicFold m a c
    lmap a -> b
    f ReifiedMonadicFold m b c
    l = MonadicFold m a c -> ReifiedMonadicFold m a c
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold ((a -> b) -> (b -> f b) -> a -> f a
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to a -> b
    f ((b -> f b) -> a -> f a)
    -> ((c -> f c) -> b -> f b) -> (c -> f c) -> a -> f a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReifiedMonadicFold m b c -> MonadicFold m b c
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m b c
    l)
      {-# INLINE lmap #-}

    instance Strong (ReifiedMonadicFold m) where
      first' :: forall a b c.
    ReifiedMonadicFold m a b -> ReifiedMonadicFold m (a, c) (b, c)
    first' ReifiedMonadicFold m a b
    l = MonadicFold m (a, c) (b, c) -> ReifiedMonadicFold m (a, c) (b, c)
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m (a, c) (b, c) -> ReifiedMonadicFold m (a, c) (b, c))
    -> MonadicFold m (a, c) (b, c)
    -> ReifiedMonadicFold m (a, c) (b, c)
    forall a b. (a -> b) -> a -> b
    $ \(b, c) -> f (b, c)
    f (a
    s,c
    c) ->
        f a -> f (a, c)
    forall (f :: * -> *) a b.
    (Functor f, Contravariant f) =>
    f a -> f b
    phantom (f a -> f (a, c)) -> f a -> f (a, c)
    forall a b. (a -> b) -> a -> b
    $ ReifiedMonadicFold m a b -> MonadicFold m a b
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m a b
    l ((b -> (b, c))
    -> (f (b, c) -> f b) -> ((b, c) -> f (b, c)) -> b -> f b
    forall a b c d. (a -> b) -> (c -> d) -> (b -> c) -> a -> d
    forall (p :: * -> * -> *) a b c d.
    Profunctor p =>
    (a -> b) -> (c -> d) -> p b c -> p a d
    dimap ((b -> c -> (b, c)) -> c -> b -> (b, c)
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip (,) c
    c) f (b, c) -> f b
    forall (f :: * -> *) a b.
    (Functor f, Contravariant f) =>
    f a -> f b
    phantom (b, c) -> f (b, c)
    f) a
    s
      {-# INLINE first' #-}
      second' :: forall a b c.
    ReifiedMonadicFold m a b -> ReifiedMonadicFold m (c, a) (c, b)
    second' ReifiedMonadicFold m a b
    l = MonadicFold m (c, a) (c, b) -> ReifiedMonadicFold m (c, a) (c, b)
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m (c, a) (c, b) -> ReifiedMonadicFold m (c, a) (c, b))
    -> MonadicFold m (c, a) (c, b)
    -> ReifiedMonadicFold m (c, a) (c, b)
    forall a b. (a -> b) -> a -> b
    $ \(c, b) -> f (c, b)
    f (c
    c,a
    s) ->
        f a -> f (c, a)
    forall (f :: * -> *) a b.
    (Functor f, Contravariant f) =>
    f a -> f b
    phantom (f a -> f (c, a)) -> f a -> f (c, a)
    forall a b. (a -> b) -> a -> b
    $ ReifiedMonadicFold m a b -> MonadicFold m a b
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m a b
    l ((b -> (c, b))
    -> (f (c, b) -> f b) -> ((c, b) -> f (c, b)) -> b -> f b
    forall a b c d. (a -> b) -> (c -> d) -> (b -> c) -> a -> d
    forall (p :: * -> * -> *) a b c d.
    Profunctor p =>
    (a -> b) -> (c -> d) -> p b c -> p a d
    dimap ((,) c
    c) f (c, b) -> f b
    forall (f :: * -> *) a b.
    (Functor f, Contravariant f) =>
    f a -> f b
    phantom (c, b) -> f (c, b)
    f) a
    s
      {-# INLINE second' #-}

    instance Choice (ReifiedMonadicFold m) where
      left' :: forall a b c.
    ReifiedMonadicFold m a b
    -> ReifiedMonadicFold m (Either a c) (Either b c)
    left' (MonadicFold MonadicFold m a b
    l) = MonadicFold m (Either a c) (Either b c)
    -> ReifiedMonadicFold m (Either a c) (Either b c)
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m (Either a c) (Either b c)
     -> ReifiedMonadicFold m (Either a c) (Either b c))
    -> MonadicFold m (Either a c) (Either b c)
    -> ReifiedMonadicFold m (Either a c) (Either b c)
    forall a b. (a -> b) -> a -> b
    $
        (Either a c -> (Maybe a, Maybe c))
    -> ((Maybe a, Maybe c) -> f (Maybe a, Maybe c))
    -> Either a c
    -> f (Either a c)
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to Either a c -> (Maybe a, Maybe c)
    forall {a} {a}. Either a a -> (Maybe a, Maybe a)
    tuplify(((Maybe a, Maybe c) -> f (Maybe a, Maybe c))
     -> Either a c -> f (Either a c))
    -> ((Either b c -> f (Either b c))
        -> (Maybe a, Maybe c) -> f (Maybe a, Maybe c))
    -> (Either b c -> f (Either b c))
    -> Either a c
    -> f (Either a c)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .Optical (->) (->) f (Maybe a) (Maybe a) (Either b c) (Either b c)
    -> Optical
         (->) (->) f (Maybe c) (Maybe c) (Either b c) (Either b c)
    -> (Either b c -> f (Either b c))
    -> (Maybe a, Maybe c)
    -> f (Maybe a, Maybe c)
    forall (q :: * -> * -> *) (f :: * -> *) (r :: * -> * -> *)
           (p :: * -> * -> *) s t a b s' t'.
    (Representable q, Applicative (Rep q), Applicative f,
     Bitraversable r) =>
    Optical p q f s t a b
    -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b
    beside ((a -> f a) -> Maybe a -> f (Maybe a)
    forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
    IndexedFold Int (Maybe a) a
    folded((a -> f a) -> Maybe a -> f (Maybe a))
    -> ((Either b c -> f (Either b c)) -> a -> f a)
    -> Optical
         (->) (->) f (Maybe a) (Maybe a) (Either b c) (Either b c)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(b -> f b) -> a -> f a
    MonadicFold m a b
    l((b -> f b) -> a -> f a)
    -> ((Either b c -> f (Either b c)) -> b -> f b)
    -> (Either b c -> f (Either b c))
    -> a
    -> f a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(b -> Either b c) -> (Either b c -> f (Either b c)) -> b -> f b
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to b -> Either b c
    forall a b. a -> Either a b
    Left) ((c -> f c) -> Maybe c -> f (Maybe c)
    forall (f :: * -> *) a. Foldable f => IndexedFold Int (f a) a
    IndexedFold Int (Maybe c) c
    folded((c -> f c) -> Maybe c -> f (Maybe c))
    -> ((Either b c -> f (Either b c)) -> c -> f c)
    -> Optical
         (->) (->) f (Maybe c) (Maybe c) (Either b c) (Either b c)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(c -> Either b c) -> (Either b c -> f (Either b c)) -> c -> f c
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to c -> Either b c
    forall a b. b -> Either a b
    Right)
        where
          tuplify :: Either a a -> (Maybe a, Maybe a)
    tuplify (Left a
    lval) = (a -> Maybe a
    forall a. a -> Maybe a
    Just a
    lval,Maybe a
    forall a. Maybe a
    Nothing)
          tuplify (Right a
    rval) = (Maybe a
    forall a. Maybe a
    Nothing,a -> Maybe a
    forall a. a -> Maybe a
    Just a
    rval)
      {-# INLINE left' #-}

    instance Cat.Category (ReifiedMonadicFold m) where
      id :: forall a. ReifiedMonadicFold m a a
    id = MonadicFold m a a -> ReifiedMonadicFold m a a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (a -> f a) -> a -> f a
    forall a. a -> a
    MonadicFold m a a
    id
      ReifiedMonadicFold m b c
    l . :: forall b c a.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m a b -> ReifiedMonadicFold m a c
    . ReifiedMonadicFold m a b
    r = MonadicFold m a c -> ReifiedMonadicFold m a c
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (ReifiedMonadicFold m a b -> MonadicFold m a b
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m a b
    r ((b -> f b) -> a -> f a)
    -> ((c -> f c) -> b -> f b) -> (c -> f c) -> a -> f a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ReifiedMonadicFold m b c -> MonadicFold m b c
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m b c
    l)
      {-# INLINE (.) #-}

    instance Arrow (ReifiedMonadicFold m) where
      arr :: forall b c. (b -> c) -> ReifiedMonadicFold m b c
    arr b -> c
    f = MonadicFold m b c -> ReifiedMonadicFold m b c
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold ((b -> c) -> (c -> f c) -> b -> f b
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to b -> c
    f)
      {-# INLINE arr #-}
      first :: forall b c d.
    ReifiedMonadicFold m b c -> ReifiedMonadicFold m (b, d) (c, d)
    first = ReifiedMonadicFold m b c -> ReifiedMonadicFold m (b, d) (c, d)
    forall b c d.
    ReifiedMonadicFold m b c -> ReifiedMonadicFold m (b, d) (c, d)
    forall (p :: * -> * -> *) a b c.
    Strong p =>
    p a b -> p (a, c) (b, c)
    first'
      {-# INLINE first #-}
      second :: forall b c d.
    ReifiedMonadicFold m b c -> ReifiedMonadicFold m (d, b) (d, c)
    second = ReifiedMonadicFold m b c -> ReifiedMonadicFold m (d, b) (d, c)
    forall b c d.
    ReifiedMonadicFold m b c -> ReifiedMonadicFold m (d, b) (d, c)
    forall (p :: * -> * -> *) a b c.
    Strong p =>
    p a b -> p (c, a) (c, b)
    second'
      {-# INLINE second #-}

    instance ArrowChoice (ReifiedMonadicFold m) where
      left :: forall b c d.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either b d) (Either c d)
    left = ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either b d) (Either c d)
    forall b c d.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either b d) (Either c d)
    forall (p :: * -> * -> *) a b c.
    Choice p =>
    p a b -> p (Either a c) (Either b c)
    left'
      {-# INLINE left #-}
      right :: forall b c d.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either d b) (Either d c)
    right = ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either d b) (Either d c)
    forall b c d.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (Either d b) (Either d c)
    forall (p :: * -> * -> *) a b c.
    Choice p =>
    p a b -> p (Either c a) (Either c b)
    right'
      {-# INLINE right #-}

    instance ArrowApply (ReifiedMonadicFold m) where
      app :: forall b c. ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    app = MonadicFold m (ReifiedMonadicFold m b c, b) c
    -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m (ReifiedMonadicFold m b c, b) c
     -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c)
    -> MonadicFold m (ReifiedMonadicFold m b c, b) c
    -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    forall a b. (a -> b) -> a -> b
    $ \c -> f c
    cHandler (ReifiedMonadicFold m b c
    argFold,b
    b) ->
         ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    -> MonadicFold m (ReifiedMonadicFold m b c, b) c
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold (b -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) b
    forall a. a -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure b
    b ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) b
    -> ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> ReifiedMonadicFold m b c
    argFold) c -> f c
    cHandler (ReifiedMonadicFold m b c
    argFold,b
    b)
      {-# INLINE app #-}

    instance Functor (ReifiedMonadicFold m s) where
      fmap :: forall a b.
    (a -> b) -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s b
    fmap a -> b
    f ReifiedMonadicFold m s a
    l = MonadicFold m s b -> ReifiedMonadicFold m s b
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (ReifiedMonadicFold m s a -> MonadicFold m s a
    forall (m :: * -> *) s a.
    ReifiedMonadicFold m s a -> MonadicFold m s a
    runMonadicFold ReifiedMonadicFold m s a
    l((a -> f a) -> s -> f s)
    -> ((b -> f b) -> a -> f a) -> (b -> f b) -> s -> f s
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(a -> b) -> (b -> f b) -> a -> f a
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to a -> b
    f)
      {-# INLINE fmap #-}

    instance Apply (ReifiedMonadicFold m s) where
      ReifiedMonadicFold m s (a -> b)
    mf <.> :: forall a b.
    ReifiedMonadicFold m s (a -> b)
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s b
    <.> ReifiedMonadicFold m s a
    ma = ReifiedMonadicFold m s (a -> b)
    mf ReifiedMonadicFold m s (a -> b)
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s (a -> b, a)
    forall b c c'.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m b c' -> ReifiedMonadicFold m b (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& ReifiedMonadicFold m s a
    ma ReifiedMonadicFold m s (a -> b, a)
    -> ReifiedMonadicFold m (a -> b, a) b -> ReifiedMonadicFold m s b
    forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> (MonadicFold m (a -> b, a) b -> ReifiedMonadicFold m (a -> b, a) b
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m (a -> b, a) b -> ReifiedMonadicFold m (a -> b, a) b)
    -> MonadicFold m (a -> b, a) b
    -> ReifiedMonadicFold m (a -> b, a) b
    forall a b. (a -> b) -> a -> b
    $ ((a -> b, a) -> b) -> (b -> f b) -> (a -> b, a) -> f (a -> b, a)
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to (((a -> b) -> a -> b) -> (a -> b, a) -> b
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry (a -> b) -> a -> b
    forall a b. (a -> b) -> a -> b
    ($)))
      {-# INLINE (<.>) #-}

    instance Applicative (ReifiedMonadicFold m s) where
      pure :: forall a. a -> ReifiedMonadicFold m s a
    pure a
    a = MonadicFold m s a -> ReifiedMonadicFold m s a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m s a -> ReifiedMonadicFold m s a)
    -> MonadicFold m s a -> ReifiedMonadicFold m s a
    forall a b. (a -> b) -> a -> b
    $ (s -> [a]) -> Fold s a
    forall (f :: * -> *) s a. Foldable f => (s -> f a) -> Fold s a
    folding ((s -> [a]) -> Fold s a) -> (s -> [a]) -> Fold s a
    forall a b. (a -> b) -> a -> b
    $ \s
    _ -> [a
    a]
      {-# INLINE pure #-}
      ReifiedMonadicFold m s (a -> b)
    mf <*> :: forall a b.
    ReifiedMonadicFold m s (a -> b)
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s b
    <*> ReifiedMonadicFold m s a
    ma = ReifiedMonadicFold m s (a -> b)
    mf ReifiedMonadicFold m s (a -> b)
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s b
    forall a b.
    ReifiedMonadicFold m s (a -> b)
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s b
    forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
    <.> ReifiedMonadicFold m s a
    ma
      {-# INLINE (<*>) #-}

    instance Alternative (ReifiedMonadicFold m s) where
      empty :: forall a. ReifiedMonadicFold m s a
    empty = MonadicFold m s a -> ReifiedMonadicFold m s a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (a -> f a) -> s -> f s
    MonadicFold m s a
    forall (f :: * -> *) pafb s. Applicative f => pafb -> s -> f s
    ignored
      {-# INLINE empty #-}
      MonadicFold MonadicFold m s a
    ma <|> :: forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    <|> MonadicFold MonadicFold m s a
    mb = MonadicFold m s a -> ReifiedMonadicFold m s a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (MonadicFold m s a -> ReifiedMonadicFold m s a)
    -> MonadicFold m s a -> ReifiedMonadicFold m s a
    forall a b. (a -> b) -> a -> b
    $ (s -> (s, s)) -> ((s, s) -> f (s, s)) -> s -> f s
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to (\s
    x->(s
    x,s
    x))(((s, s) -> f (s, s)) -> s -> f s)
    -> ((a -> f a) -> (s, s) -> f (s, s)) -> (a -> f a) -> s -> f s
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .((a -> f a) -> s -> f s)
    -> ((a -> f a) -> s -> f s) -> (a -> f a) -> (s, s) -> f (s, s)
    forall (q :: * -> * -> *) (f :: * -> *) (r :: * -> * -> *)
           (p :: * -> * -> *) s t a b s' t'.
    (Representable q, Applicative (Rep q), Applicative f,
     Bitraversable r) =>
    Optical p q f s t a b
    -> Optical p q f s' t' a b -> Optical p q f (r s s') (r t t') a b
    beside (a -> f a) -> s -> f s
    MonadicFold m s a
    ma (a -> f a) -> s -> f s
    MonadicFold m s a
    mb
      {-# INLINE (<|>) #-}

    instance Bind (ReifiedMonadicFold m s) where
      ReifiedMonadicFold m s a
    ma >>- :: forall a b.
    ReifiedMonadicFold m s a
    -> (a -> ReifiedMonadicFold m s b) -> ReifiedMonadicFold m s b
    >>- a -> ReifiedMonadicFold m s b
    f = ((ReifiedMonadicFold m s a
    ma ReifiedMonadicFold m s a
    -> (a -> ReifiedMonadicFold m s b)
    -> ReifiedMonadicFold m s (ReifiedMonadicFold m s b)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> (c -> d) -> a b d
    >>^ a -> ReifiedMonadicFold m s b
    f) ReifiedMonadicFold m s (ReifiedMonadicFold m s b)
    -> ReifiedMonadicFold m s s
    -> ReifiedMonadicFold m s (ReifiedMonadicFold m s b, s)
    forall b c c'.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m b c' -> ReifiedMonadicFold m b (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& ReifiedMonadicFold m s s
    forall (a :: * -> * -> *) b. Arrow a => a b b
    returnA) ReifiedMonadicFold m s (ReifiedMonadicFold m s b, s)
    -> ReifiedMonadicFold m (ReifiedMonadicFold m s b, s) b
    -> ReifiedMonadicFold m s b
    forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> ReifiedMonadicFold m (ReifiedMonadicFold m s b, s) b
    forall b c. ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
    app
      {-# INLINE (>>-) #-}

    instance Monad (ReifiedMonadicFold m s) where
    #if !(MIN_VERSION_base(4,11,0))
      return a = MonadicFold $ folding $ \_ -> [a]
      {-# INLINE return #-}
    #endif
      ReifiedMonadicFold m s a
    ma >>= :: forall a b.
    ReifiedMonadicFold m s a
    -> (a -> ReifiedMonadicFold m s b) -> ReifiedMonadicFold m s b
    >>= a -> ReifiedMonadicFold m s b
    f = ((ReifiedMonadicFold m s a
    ma ReifiedMonadicFold m s a
    -> (a -> ReifiedMonadicFold m s b)
    -> ReifiedMonadicFold m s (ReifiedMonadicFold m s b)
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    a b c -> (c -> d) -> a b d
    >>^ a -> ReifiedMonadicFold m s b
    f) ReifiedMonadicFold m s (ReifiedMonadicFold m s b)
    -> ReifiedMonadicFold m s s
    -> ReifiedMonadicFold m s (ReifiedMonadicFold m s b, s)
    forall b c c'.
    ReifiedMonadicFold m b c
    -> ReifiedMonadicFold m b c' -> ReifiedMonadicFold m b (c, c')
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&& ReifiedMonadicFold m s s
    forall (a :: * -> * -> *) b. Arrow a => a b b
    returnA) ReifiedMonadicFold m s (ReifiedMonadicFold m s b, s)
    -> ReifiedMonadicFold m (ReifiedMonadicFold m s b, s) b
    -> ReifiedMonadicFold m s b
    forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> ReifiedMonadicFold m (ReifiedMonadicFold m s b, s) b
    forall b c. ReifiedMonadicFold m (ReifiedMonadicFold m b c, b) c
    forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
    app
      {-# INLINE (>>=) #-}

    instance MonadReader s (ReifiedMonadicFold m s) where
      ask :: ReifiedMonadicFold m s s
    ask = ReifiedMonadicFold m s s
    forall (a :: * -> * -> *) b. Arrow a => a b b
    returnA
      {-# INLINE ask #-}
      local :: forall a.
    (s -> s) -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    local s -> s
    f ReifiedMonadicFold m s a
    ma = s -> s
    f (s -> s) -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall (a :: * -> * -> *) b c d.
    Arrow a =>
    (b -> c) -> a c d -> a b d
    ^>> ReifiedMonadicFold m s a
    ma
      {-# INLINE local #-}

    instance MonadPlus (ReifiedMonadicFold m s) where
      mzero :: forall a. ReifiedMonadicFold m s a
    mzero = ReifiedMonadicFold m s a
    forall a. ReifiedMonadicFold m s a
    forall (f :: * -> *) a. Alternative f => f a
    empty
      {-# INLINE mzero #-}
      mplus :: forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    mplus = ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    (<|>)
      {-# INLINE mplus #-}

    instance Semigroup (ReifiedMonadicFold m s a) where
      <> :: ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    (<>) = ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    (<|>)
      {-# INLINE (<>) #-}

    instance Monoid (ReifiedMonadicFold m s a) where
      mempty :: ReifiedMonadicFold m s a
    mempty = MonadicFold m s a -> ReifiedMonadicFold m s a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (a -> f a) -> s -> f s
    MonadicFold m s a
    forall (f :: * -> *) pafb s. Applicative f => pafb -> s -> f s
    ignored
      {-# INLINE mempty #-}
    #if !(MIN_VERSION_base(4,11,0))
      mappend = (<|>)
      {-# INLINE mappend #-}
    #endif

    instance Alt (ReifiedMonadicFold m s) where
      <!> :: forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    (<!>) = ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall a.
    ReifiedMonadicFold m s a
    -> ReifiedMonadicFold m s a -> ReifiedMonadicFold m s a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    (<|>)
      {-# INLINE (<!>) #-}

    instance Plus (ReifiedMonadicFold m s) where
      zero :: forall a. ReifiedMonadicFold m s a
    zero = MonadicFold m s a -> ReifiedMonadicFold m s a
    forall (m :: * -> *) s a.
    MonadicFold m s a -> ReifiedMonadicFold m s a
    MonadicFold (a -> f a) -> s -> f s
    MonadicFold m s a
    forall (f :: * -> *) pafb s. Applicative f => pafb -> s -> f s
    ignored
      {-# INLINE zero #-}