{-# LANGUAGE DerivingVia #-}

-- |
-- Module      : Data.HBifunctor.Associative
-- Copyright   : (c) Justin Le 2019
-- License     : BSD3
--
-- Maintainer  : justin@jle.im
-- Stability   : experimental
-- Portability : non-portable
--
-- This module provides tools for working with binary functor combinators
-- that represent interpretable schemas.
--
-- These are types @'HBifunctor' t@ that take two functors @f@ and @g@ and returns a new
-- functor @t f g@, that "mixes together" @f@ and @g@ in some way.
--
-- The high-level usage of this is
--
-- @
-- 'biretract' :: 'SemigroupIn' t f => t f f ~> f
-- @
--
-- which lets you fully "mix" together the two input functors.
--
-- @
-- 'biretract' :: (f ':+:' f) a -> f a
-- biretract :: 'Plus' f => (f ':*:' f) a -> f a
-- biretract :: 'Applicative' f => 'Day' f f a -> f a
-- biretract :: 'Monad' f => 'Comp' f f a -> f a
-- @
--
-- See "Data.HBifunctor.Tensor" for the next stage of structure in tensors
-- and moving in and out of them.
module Data.HBifunctor.Associative (
  -- * 'Associative'
    Associative(..)
  , assoc
  , disassoc
  -- * 'SemigroupIn'
  , SemigroupIn(..)
  , matchingNE
  , retractNE
  , interpretNE
  -- ** Utility
  , biget
  , biapply
  , (!*!)
  , (!$!)
  , (!+!)
  , WrapHBF(..)
  , WrapNE(..)
  ) where

import           Control.Applicative.ListF
import           Control.Applicative.Step
import           Control.Monad.Freer.Church
import           Control.Monad.Trans.Compose
import           Control.Monad.Trans.Identity
import           Control.Natural
import           Control.Natural.IsoF
import           Data.Bifunctor
import           Data.Bifunctor.Joker
import           Data.Coerce
import           Data.Constraint.Trivial
import           Data.Data
import           Data.Foldable
import           Data.Functor.Apply.Free
import           Data.Functor.Bind
import           Data.Functor.Classes
import           Data.Functor.Contravariant
import           Data.Functor.Contravariant.Decide
import           Data.Functor.Contravariant.Divise
import           Data.Functor.Contravariant.Divisible.Free
import           Data.Functor.Contravariant.Night          (Night(..))
import           Data.Functor.Day                          (Day(..))
import           Data.Functor.Identity
import           Data.Functor.Invariant
import           Data.Functor.Invariant.Inplicative
import           Data.Functor.Invariant.Internative
import           Data.Functor.Plus
import           Data.Functor.Product
import           Data.Functor.Sum
import           Data.Functor.These
import           Data.HBifunctor
import           Data.HFunctor
import           Data.HFunctor.Chain.Internal
import           Data.HFunctor.Internal
import           Data.HFunctor.Interpret
import           Data.Kind
import           Data.List.NonEmpty                        (NonEmpty(..))
import           Data.Void
import           GHC.Generics
import qualified Data.Bifunctor.Assoc                      as B
import qualified Data.Functor.Contravariant.Coyoneda       as CCY
import qualified Data.Functor.Contravariant.Day            as CD
import qualified Data.Functor.Contravariant.Night          as N
import qualified Data.Functor.Day                          as D
import qualified Data.Functor.Invariant.Day                as ID
import qualified Data.Functor.Invariant.Night              as IN
import qualified Data.Map.NonEmpty                         as NEM

-- | An 'HBifunctor' where it doesn't matter which binds first is
-- 'Associative'.  Knowing this gives us a lot of power to rearrange the
-- internals of our 'HFunctor' at will.
--
-- For example, for the functor product:
--
-- @
-- data (f ':*:' g) a = f a :*: g a
-- @
--
-- We know that @f :*: (g :*: h)@ is the same as @(f :*: g) :*: h@.
--
-- Formally, we can say that @t@ enriches a the category of
-- endofunctors with semigroup strcture: it turns our endofunctor category
-- into a "semigroupoidal category".
--
-- Different instances of @t@ each enrich the endofunctor category in
-- different ways, giving a different semigroupoidal category.
class (HBifunctor t, Inject (NonEmptyBy t)) => Associative t where
    -- | The "semigroup functor combinator" generated by @t@.
    --
    -- A value of type @NonEmptyBy t f a@ is /equivalent/ to one of:
    --
    -- *  @f a@
    -- *  @t f f a@
    -- *  @t f (t f f) a@
    -- *  @t f (t f (t f f)) a@
    -- *  @t f (t f (t f (t f f))) a@
    -- *  .. etc
    --
    -- For example, for ':*:', we have 'NonEmptyF'.  This is because:
    --
    -- @
    -- x             ~ 'NonEmptyF' (x ':|' [])      ~ 'inject' x
    -- x ':*:' y       ~ NonEmptyF (x :| [y])     ~ 'toNonEmptyBy' (x :*: y)
    -- x :*: y :*: z ~ NonEmptyF (x :| [y,z])
    -- -- etc.
    -- @
    --
    -- You can create an "singleton" one with 'inject', or else one from
    -- a single @t f f@ with 'toNonEmptyBy'.
    --
    -- See 'Data.HBifunctor.Tensor.ListBy' for a "possibly empty" version
    -- of this type.
    type NonEmptyBy t :: (Type -> Type) -> Type -> Type

    -- | A description of "what type of Functor" this tensor is expected to
    -- be applied to.  This should typically always be either 'Functor',
    -- 'Contravariant', or 'Invariant'.
    --
    -- @since 0.3.0.0
    type FunctorBy t :: (Type -> Type) -> Constraint
    type FunctorBy t = Unconstrained

    -- | The isomorphism between @t f (t g h) a@ and @t (t f g) h a@.  To
    -- use this isomorphism, see 'assoc' and 'disassoc'.
    associating
        :: (FunctorBy t f, FunctorBy t g, FunctorBy t h)
        => t f (t g h) <~> t (t f g) h

    -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@ to
    -- itself, then we can also "append" two @'NonEmptyBy' t f@s applied to
    -- themselves into one giant @'NonEmptyBy' t f@ containing all of the @t f@s.
    --
    -- Note that this essentially gives an instance for @'SemigroupIn'
    -- t (NonEmptyBy t f)@, for any functor @f@.
    appendNE :: t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f

    -- | If a @'NonEmptyBy' t f@ represents multiple applications of @t f@
    -- to itself, then we can split it based on whether or not it is just
    -- a single @f@ or at least one top-level application of @t f@.
    --
    -- Note that you can recursively "unroll" a 'NonEmptyBy' completely
    -- into a 'Data.HFunctor.Chain.Chain1' by using
    -- 'Data.HFunctor.Chain.unrollNE'.
    matchNE  :: FunctorBy t f => NonEmptyBy t f ~> f :+: t f (NonEmptyBy t f)

    -- | Prepend an application of @t f@ to the front of a @'NonEmptyBy' t f@.
    consNE :: t f (NonEmptyBy t f) ~> NonEmptyBy t f
    consNE = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject

    -- | Embed a direct application of @f@ to itself into a @'NonEmptyBy' t f@.
    toNonEmptyBy :: t f f ~> NonEmptyBy t f
    toNonEmptyBy = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject

    {-# MINIMAL associating, appendNE, matchNE #-}

-- | Reassociate an application of @t@.
assoc
    :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h)
    => t f (t g h)
    ~> t (t f g) h
assoc :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) ~> t (t f g) h
assoc = forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> f ~> g
viewF forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) <~> t (t f g) h
associating

-- | Reassociate an application of @t@.
disassoc
    :: (Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h)
    => t (t f g) h
    ~> t f (t g h)
disassoc :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t (t f g) h ~> t f (t g h)
disassoc = forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> g ~> f
reviewF forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) <~> t (t f g) h
associating

-- | For different @'Associative' t@, we have functors @f@ that we can
-- "squash", using 'biretract':
--
-- @
-- t f f ~> f
-- @
--
-- This gives us the ability to squash applications of @t@.
--
-- Formally, if we have @'Associative' t@, we are enriching the category of
-- endofunctors with semigroup structure, turning it into a semigroupoidal
-- category.  Different choices of @t@ give different semigroupoidal
-- categories.
--
-- A functor @f@ is known as a "semigroup in the (semigroupoidal) category
-- of endofunctors on @t@" if we can 'biretract':
--
-- @
-- t f f ~> f
-- @
--
-- This gives us a few interesting results in category theory, which you
-- can stil reading about if you don't care:
--
-- *  /All/ functors are semigroups in the semigroupoidal category
--    on ':+:'
-- *  The class of functors that are semigroups in the semigroupoidal
--    category on ':*:' is exactly the functors that are instances of
--    'Alt'.
-- *  The class of functors that are semigroups in the semigroupoidal
--    category on 'Day' is exactly the functors that are instances of
--    'Apply'.
-- *  The class of functors that are semigroups in the semigroupoidal
--    category on 'Comp' is exactly the functors that are instances of
--    'Bind'.
--
-- Note that instances of this class are /intended/ to be written with @t@
-- as a fixed type constructor, and @f@ to be allowed to vary freely:
--
-- @
-- instance Bind f => SemigroupIn Comp f
-- @
--
-- Any other sort of instance and it's easy to run into problems with type
-- inference.  If you want to write an instance that's "polymorphic" on
-- tensor choice, use the 'WrapHBF' newtype wrapper over a type variable,
-- where the second argument also uses a type constructor:
--
-- @
-- instance SemigroupIn (WrapHBF t) (MyFunctor t i)
-- @
--
-- This will prevent problems with overloaded instances.
class (Associative t, FunctorBy t f) => SemigroupIn t f where
    -- | The 'HBifunctor' analogy of 'retract'. It retracts /both/ @f@s
    -- into a single @f@, effectively fully mixing them together.
    --
    -- This function makes @f@ a semigroup in the category of endofunctors
    -- with respect to tensor @t@.
    biretract :: t f f ~> f

    default biretract :: Interpret (NonEmptyBy t) f => t f f ~> f
    biretract = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Interpret t f =>
t f ~> f
retract forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject

    -- | The 'HBifunctor' analogy of 'interpret'.  It takes two
    -- interpreting functions, and mixes them together into a target
    -- functor @h@.
    --
    -- Note that this is useful in the poly-kinded case, but it is not possible
    -- to define generically for all 'SemigroupIn' because it only is defined
    -- for @Type -> Type@ inputes.  See '!+!' for a version that is poly-kinded
    -- for ':+:' in specific.
    binterpret
        :: g ~> f
        -> h ~> f
        -> t g h ~> f

    default binterpret :: Interpret (NonEmptyBy t) f => (g ~> f) -> (h ~> f) -> t g h ~> f
    binterpret g ~> f
f h ~> f
g = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Interpret t f =>
t f ~> f
retract forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *) (l :: k -> *).
HBifunctor t =>
(f ~> j) -> (g ~> l) -> t f g ~> t j l
hbimap g ~> f
f h ~> f
g

-- | An implementation of 'retract' that works for any instance of
-- @'SemigroupIn' t@ for @'NonEmptyBy' t@.
--
-- Can be useful as a default implementation if you already have
-- 'SemigroupIn' implemented.
retractNE :: forall t f. SemigroupIn t f => NonEmptyBy t f ~> f
retractNE :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
NonEmptyBy t f ~> f
retractNE = (forall a. a -> a
id forall (t :: (* -> *) -> (* -> *) -> * -> *) (h :: * -> *)
       (f :: * -> *) (g :: * -> *).
SemigroupIn t h =>
(f ~> h) -> (g ~> h) -> t f g ~> h
!*! forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
t f f ~> f
biretract @t forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright (forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
NonEmptyBy t f ~> f
retractNE @t))
          forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE @t

-- | An implementation of 'interpret' that works for any instance of
-- @'SemigroupIn' t@ for @'NonEmptyBy' t@.
--
-- Can be useful as a default implementation if you already have
-- 'SemigroupIn' implemented.
interpretNE :: forall t g f. SemigroupIn t f => (g ~> f) -> NonEmptyBy t g ~> f
interpretNE :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (g :: * -> *)
       (f :: * -> *).
SemigroupIn t f =>
(g ~> f) -> NonEmptyBy t g ~> f
interpretNE g ~> f
f = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
NonEmptyBy t f ~> f
retractNE @t forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap g ~> f
f

-- | An @'NonEmptyBy' t f@ represents the successive application of @t@ to @f@,
-- over and over again.   So, that means that an @'NonEmptyBy' t f@ must either be
-- a single @f@, or an @t f (NonEmptyBy t f)@.
--
-- 'matchingNE' states that these two are isomorphic.  Use 'matchNE' and
-- @'inject' '!*!' 'consNE'@ to convert between one and the other.
matchingNE :: (Associative t, FunctorBy t f) => NonEmptyBy t f <~> f :+: t f (NonEmptyBy t f)
matchingNE :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f <~> (f :+: t f (NonEmptyBy t f))
matchingNE = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE (forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject forall (t :: (* -> *) -> (* -> *) -> * -> *) (h :: * -> *)
       (f :: * -> *) (g :: * -> *).
SemigroupIn t h =>
(f ~> h) -> (g ~> h) -> t f g ~> h
!*! forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE)

-- | Useful wrapper over 'binterpret' to allow you to directly extract
-- a value @b@ out of the @t f g a@, if you can convert an @f x@ and @g x@
-- into @b@.
--
-- Note that depending on the constraints on @h@ in @'SemigroupIn' t h@,
-- you may have extra constraints on @b@.
--
-- *    If @h@ is unconstrained, there are no constraints on @b@
-- *    If @h@ must be 'Apply', 'Alt', 'Divise', or 'Decide', @b@ needs to be an instance of 'Semigroup'
-- *    If @h@ is 'Applicative', 'Plus',
--      'Data.Functor.Contravariant.Divisible.Divisible', or
--      'Data.Functor.Contravariant.Conclude.Conclude', @b@ needs to be an
--      instance of 'Monoid'
--
-- For some constraints (like 'Monad'), this will not be usable.
--
-- @
-- -- Return the length of either the list, or the Map, depending on which
-- --   one s in the '+'
-- 'biget' 'length' length
--     :: ([] :+: 'Data.Map.Map' 'Int') 'Char'
--     -> Int
--
-- -- Return the length of both the list and the map, added together
-- 'biget' ('Data.Monoid.Sum' . length) (Sum . length)
--     :: 'Day' [] (Map Int) Char
--     -> Sum Int
-- @
biget
    :: SemigroupIn t (AltConst b)
    => (forall x. f x -> b)
    -> (forall x. g x -> b)
    -> t f g a
    -> b
biget :: forall (t :: (* -> *) -> (* -> *) -> * -> *) b (f :: * -> *)
       (g :: * -> *) a.
SemigroupIn t (AltConst b) =>
(forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
biget forall x. f x -> b
f forall x. g x -> b
g = forall {k} w (a :: k). AltConst w a -> w
getAltConst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
SemigroupIn t f =>
(g ~> f) -> (h ~> f) -> t g h ~> f
binterpret (forall {k} w (a :: k). w -> AltConst w a
AltConst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> b
f) (forall {k} w (a :: k). w -> AltConst w a
AltConst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. g x -> b
g)

-- | Infix alias for 'biget'
--
-- @
-- -- Return the length of either the list, or the Map, depending on which
-- --   one s in the '+'
-- 'length' '!$!' length
--     :: ([] :+: 'Data.Map.Map' 'Int') 'Char'
--     -> Int
--
-- -- Return the length of both the list and the map, added together
-- 'Data.Monoid.Sum' . length !$! Sum . length
--     :: 'Day' [] (Map Int) Char
--     -> Sum Int
-- @
(!$!)
    :: SemigroupIn t (AltConst b)
    => (forall x. f x -> b)
    -> (forall x. g x -> b)
    -> t f g a
    -> b
!$! :: forall (t :: (* -> *) -> (* -> *) -> * -> *) b (f :: * -> *)
       (g :: * -> *) a.
SemigroupIn t (AltConst b) =>
(forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
(!$!) = forall (t :: (* -> *) -> (* -> *) -> * -> *) b (f :: * -> *)
       (g :: * -> *) a.
SemigroupIn t (AltConst b) =>
(forall x. f x -> b) -> (forall x. g x -> b) -> t f g a -> b
biget
infixr 5 !$!

-- | Infix alias for 'binterpret'
--
-- Note that this is useful in the poly-kinded case, but it is not possible
-- to define generically for all 'SemigroupIn' because it only is defined
-- for @Type -> Type@ inputes.  See '!+!' for a version that is poly-kinded
-- for ':+:' in specific.
(!*!)
    :: SemigroupIn t h
    => (f ~> h)
    -> (g ~> h)
    -> t f g
    ~> h
!*! :: forall (t :: (* -> *) -> (* -> *) -> * -> *) (h :: * -> *)
       (f :: * -> *) (g :: * -> *).
SemigroupIn t h =>
(f ~> h) -> (g ~> h) -> t f g ~> h
(!*!) = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
SemigroupIn t f =>
(g ~> f) -> (h ~> f) -> t g h ~> f
binterpret
infixr 5 !*!

-- | A version of '!*!' specifically for ':+:' that is poly-kinded
(!+!)
    :: (f ~> h)
    -> (g ~> h)
    -> (f :+: g)
    ~> h
!+! :: forall {k} (f :: k -> *) (h :: k -> *) (g :: k -> *).
(f ~> h) -> (g ~> h) -> (f :+: g) ~> h
(!+!) f ~> h
f g ~> h
g = \case
    L1 f x
x -> f ~> h
f f x
x
    R1 g x
y -> g ~> h
g g x
y
infixr 5 !+!

-- | Useful wrapper over 'binterpret' to allow you to directly extract
-- a value @b@ out of the @t f g a@, if you can convert an @f x@ and @g x@
-- into @b@, given an @x@ input.
--
-- Note that depending on the constraints on @h@ in @'SemigroupIn' t h@,
-- you may have extra constraints on @b@.
--
-- *    If @h@ is unconstrained, there are no constraints on @b@
-- *    If @h@ must be 'Divise', or 'Divisible', @b@ needs to be an instance of 'Semigroup'
-- *    If @h@ must be 'Divisible', then @b@ needs to be an instance of 'Monoid'.
--
-- For some constraints (like 'Monad'), this will not be usable.
--
-- @since 0.3.2.0
biapply
    :: SemigroupIn t (Op b)
    => (forall x. f x -> x -> b)
    -> (forall x. g x -> x -> b)
    -> t f g a
    -> a
    -> b
biapply :: forall (t :: (* -> *) -> (* -> *) -> * -> *) b (f :: * -> *)
       (g :: * -> *) a.
SemigroupIn t (Op b) =>
(forall x. f x -> x -> b)
-> (forall x. g x -> x -> b) -> t f g a -> a -> b
biapply forall x. f x -> x -> b
f forall x. g x -> x -> b
g = forall a b. Op a b -> b -> a
getOp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
SemigroupIn t f =>
(g ~> f) -> (h ~> f) -> t g h ~> f
binterpret (forall a b. (b -> a) -> Op a b
Op forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. f x -> x -> b
f) (forall a b. (b -> a) -> Op a b
Op forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. g x -> x -> b
g)

instance Associative (:*:) where
    type NonEmptyBy (:*:) = NonEmptyF

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy (:*:) f, FunctorBy (:*:) g, FunctorBy (:*:) h) =>
(f :*: (g :*: h)) <~> ((f :*: g) :*: h)
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {f :: k -> *} {g :: k -> *} {g :: k -> *} {p :: k}.
(:*:) f (g :*: g) p -> (:*:) (f :*: g) g p
to_ forall {k} {f :: k -> *} {f :: k -> *} {g :: k -> *} {p :: k}.
(:*:) (f :*: f) g p -> (:*:) f (f :*: g) p
from_
      where
        to_ :: (:*:) f (g :*: g) p -> (:*:) (f :*: g) g p
to_   (f p
x :*: (g p
y :*: g p
z)) = (f p
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g p
y) forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g p
z
        from_ :: (:*:) (f :*: f) g p -> (:*:) f (f :*: g) p
from_ ((f p
x :*: f p
y) :*: g p
z) = f p
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (f p
y forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g p
z)

    appendNE :: forall (f :: * -> *).
(NonEmptyBy (:*:) f :*: NonEmptyBy (:*:) f) ~> NonEmptyBy (:*:) f
appendNE (NonEmptyF NonEmpty (f x)
xs :*: NonEmptyF NonEmpty (f x)
ys) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x)
xs forall a. Semigroup a => a -> a -> a
<> NonEmpty (f x)
ys)
    matchNE :: forall (f :: * -> *).
FunctorBy (:*:) f =>
NonEmptyBy (:*:) f ~> (f :+: (f :*: NonEmptyBy (:*:) f))
matchNE NonEmptyBy (:*:) f x
x = case (:+:) Proxy (NonEmptyF f) x
ys of
        L1 ~Proxy x
Proxy -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
y
        R1 NonEmptyF f x
zs     -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ f x
y forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: NonEmptyF f x
zs
      where
        f x
y :*: (:+:) Proxy (NonEmptyF f) x
ys = forall {k} (f :: k -> *). ListF f ~> (Proxy :+: NonEmptyF f)
fromListF forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
`hright` forall {k} (f :: k -> *) (a :: k).
NonEmptyF f a -> (:*:) f (ListF f) a
nonEmptyProd NonEmptyBy (:*:) f x
x

    consNE :: forall (f :: * -> *).
(f :*: NonEmptyBy (:*:) f) ~> NonEmptyBy (:*:) f
consNE (f x
x :*: NonEmptyF NonEmpty (f x)
xs) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall a b. (a -> b) -> a -> b
$ f x
x forall a. a -> [a] -> NonEmpty a
:| forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (f x)
xs
    toNonEmptyBy :: forall (f :: * -> *). (f :*: f) ~> NonEmptyBy (:*:) f
toNonEmptyBy   (f x
x :*: f x
y           ) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall a b. (a -> b) -> a -> b
$ f x
x forall a. a -> [a] -> NonEmpty a
:| [f x
y]

-- | Instances of 'Alt' are semigroups in the semigroupoidal category on
-- ':*:'.
instance Alt f => SemigroupIn (:*:) f where
    biretract :: (f :*: f) ~> f
biretract (f x
x :*: f x
y) = f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> (g :*: h) ~> f
binterpret g ~> f
f h ~> f
g (g x
x :*: h x
y) = g ~> f
f g x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> h ~> f
g h x
y

instance Associative Product where
    type NonEmptyBy Product = NonEmptyF

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Product f, FunctorBy Product g, FunctorBy Product h) =>
Product f (Product g h) <~> Product (Product f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {f :: k -> *} {g :: k -> *} {g :: k -> *} {a :: k}.
Product f (Product g g) a -> Product (Product f g) g a
to_ forall {k} {f :: k -> *} {f :: k -> *} {g :: k -> *} {a :: k}.
Product (Product f f) g a -> Product f (Product f g) a
from_
      where
        to_ :: Product f (Product g g) a -> Product (Product f g) g a
to_   (Pair f a
x (Pair g a
y g a
z)) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
x g a
y) g a
z
        from_ :: Product (Product f f) g a -> Product f (Product f g) a
from_ (Pair (Pair f a
x f a
y) g a
z) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
x (forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
y g a
z)

    appendNE :: forall (f :: * -> *).
Product (NonEmptyBy Product f) (NonEmptyBy Product f)
~> NonEmptyBy Product f
appendNE (NonEmptyF NonEmpty (f x)
xs `Pair` NonEmptyF NonEmpty (f x)
ys) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x)
xs forall a. Semigroup a => a -> a -> a
<> NonEmpty (f x)
ys)
    matchNE :: forall (f :: * -> *).
FunctorBy Product f =>
NonEmptyBy Product f ~> (f :+: Product f (NonEmptyBy Product f))
matchNE NonEmptyBy Product f x
x = case (:+:) Proxy (NonEmptyF f) x
ys of
        L1 ~Proxy x
Proxy -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
y
        R1 NonEmptyF f x
zs     -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f x
y NonEmptyF f x
zs
      where
        f x
y :*: (:+:) Proxy (NonEmptyF f) x
ys = forall {k} (f :: k -> *). ListF f ~> (Proxy :+: NonEmptyF f)
fromListF forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
`hright` forall {k} (f :: k -> *) (a :: k).
NonEmptyF f a -> (:*:) f (ListF f) a
nonEmptyProd NonEmptyBy Product f x
x

    consNE :: forall (f :: * -> *).
Product f (NonEmptyBy Product f) ~> NonEmptyBy Product f
consNE (f x
x `Pair` NonEmptyF NonEmpty (f x)
xs) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall a b. (a -> b) -> a -> b
$ f x
x forall a. a -> [a] -> NonEmpty a
:| forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (f x)
xs
    toNonEmptyBy :: forall (f :: * -> *). Product f f ~> NonEmptyBy Product f
toNonEmptyBy   (f x
x `Pair` f x
y           ) = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall a b. (a -> b) -> a -> b
$ f x
x forall a. a -> [a] -> NonEmpty a
:| [f x
y]

-- | Instances of 'Alt' are semigroups in the semigroupoidal category on
-- 'Product'.
instance Alt f => SemigroupIn Product f where
    biretract :: Product f f ~> f
biretract (Pair f x
x f x
y) = f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Product g h ~> f
binterpret g ~> f
f h ~> f
g (Pair g x
x h x
y) = g ~> f
f g x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> h ~> f
g h x
y

instance Associative Day where
    type NonEmptyBy Day = Ap1
    type FunctorBy Day = Functor
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Day f, FunctorBy Day g, FunctorBy Day h) =>
Day f (Day g h) <~> Day (Day f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day f (Day g h) a -> Day (Day f g) h a
D.assoc forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day (Day f g) h a -> Day f (Day g h) a
D.disassoc

    appendNE :: forall (f :: * -> *).
Day (NonEmptyBy Day f) (NonEmptyBy Day f) ~> NonEmptyBy Day f
appendNE (Day NonEmptyBy Day f b
x NonEmptyBy Day f c
y b -> c -> x
z) = b -> c -> x
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmptyBy Day f b
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> NonEmptyBy Day f c
y
    matchNE :: forall (f :: * -> *).
FunctorBy Day f =>
NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE NonEmptyBy Day f x
a = case forall (f :: * -> *). Ap f ~> (Identity :+: Ap1 f)
fromAp forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
`hright` forall (f :: * -> *) a. Ap1 f a -> Day f (Ap f) a
ap1Day NonEmptyBy Day f x
a of
      Day f b
x (:+:) Identity (Ap1 f) c
y b -> c -> x
z -> case (:+:) Identity (Ap1 f) c
y of
        L1 (Identity c
y') -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall a b. (a -> b) -> a -> b
$ (b -> c -> x
`z` c
y') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
x
        R1 Ap1 f c
ys            -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> Day f g a
Day f b
x Ap1 f c
ys b -> c -> x
z

    consNE :: forall (f :: * -> *). Day f (NonEmptyBy Day f) ~> NonEmptyBy Day f
consNE (Day f b
x NonEmptyBy Day f c
y b -> c -> x
z) = forall (a :: * -> *) a1 b. a a1 -> Ap a (a1 -> b) -> Ap1 a b
Ap1 f b
x forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip b -> c -> x
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (f :: * -> *). Ap1 f ~> Ap f
toAp NonEmptyBy Day f c
y
    toNonEmptyBy :: forall (f :: * -> *). Day f f ~> NonEmptyBy Day f
toNonEmptyBy   (Day f b
x f c
y b -> c -> x
z) = b -> c -> x
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f b
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f c
y

-- | Instances of 'Apply' are semigroups in the semigroupoidal category on
-- 'Day'.
instance Apply f => SemigroupIn Day f where
    biretract :: Day f f ~> f
biretract (Day f b
x f c
y b -> c -> x
z) = b -> c -> x
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> f c
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Day g h ~> f
binterpret g ~> f
f h ~> f
g (Day g b
x h c
y b -> c -> x
z) = b -> c -> x
z forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g ~> f
f g b
x forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> h ~> f
g h c
y

-- | @since 0.3.0.0
instance Associative CD.Day where
    type NonEmptyBy CD.Day = Div1
    type FunctorBy CD.Day = Contravariant
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Day f, FunctorBy Day g, FunctorBy Day h) =>
Day f (Day g h) <~> Day (Day f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day f (Day g h) a -> Day (Day f g) h a
CD.assoc forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day (Day f g) h a -> Day f (Day g h) a
CD.disassoc

    appendNE :: forall (f :: * -> *).
Day (NonEmptyBy Day f) (NonEmptyBy Day f) ~> NonEmptyBy Day f
appendNE (CD.Day NonEmptyBy Day f b
x NonEmptyBy Day f c
y x -> (b, c)
f) = forall (f :: * -> *) a b c.
Divise f =>
(a -> (b, c)) -> f b -> f c -> f a
divise x -> (b, c)
f NonEmptyBy Day f b
x NonEmptyBy Day f c
y
    matchNE :: forall (f :: * -> *).
FunctorBy Day f =>
NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE = forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *) (l :: k -> *).
HBifunctor t =>
(f ~> j) -> (g ~> l) -> t f g ~> t j l
hbimap forall (f :: * -> *) a. Contravariant f => Coyoneda f a -> f a
CCY.lowerCoyoneda forall {f :: * -> *} {f :: * -> *} {p}.
(:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) p -> Day f (Div1 f) p
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE @(:*:) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Div1 f a -> NonEmpty (Coyoneda f a)
unDiv1
      where
        go :: (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) p -> Day f (Div1 f) p
go (CCY.Coyoneda p -> b
f f b
x :*: NonEmptyF NonEmpty (Coyoneda f p)
xs) = forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (a -> (b, c)) -> Day f g a
CD.Day f b
x (forall (f :: * -> *) a. NonEmpty (Coyoneda f a) -> Div1 f a
Div1 NonEmpty (Coyoneda f p)
xs) (\p
y -> (p -> b
f p
y, p
y))

    consNE :: forall (f :: * -> *). Day f (NonEmptyBy Day f) ~> NonEmptyBy Day f
consNE (CD.Day f b
x (Div1 NonEmpty (Coyoneda f c)
xs) x -> (b, c)
f) = forall (f :: * -> *) a. NonEmpty (Coyoneda f a) -> Div1 f a
Div1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NonEmptyF f a -> NonEmpty (f a)
runNonEmptyF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE forall a b. (a -> b) -> a -> b
$
        forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) f b
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap (forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) (forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF NonEmpty (Coyoneda f c)
xs)
    toNonEmptyBy :: forall (f :: * -> *). Day f f ~> NonEmptyBy Day f
toNonEmptyBy (CD.Day f b
x f c
y x -> (b, c)
f) = forall (f :: * -> *) a. NonEmpty (Coyoneda f a) -> Div1 f a
Div1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NonEmptyF f a -> NonEmpty (f a)
runNonEmptyF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy forall a b. (a -> b) -> a -> b
$
        forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) f b
x forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda (forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) f c
y

-- | @since 0.3.0.0
instance Divise f => SemigroupIn CD.Day f where
    biretract :: Day f f ~> f
biretract      (CD.Day f b
x f c
y x -> (b, c)
f) = forall (f :: * -> *) a b c.
Divise f =>
(a -> (b, c)) -> f b -> f c -> f a
divise x -> (b, c)
f f b
x f c
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Day g h ~> f
binterpret g ~> f
f h ~> f
g (CD.Day g b
x h c
y x -> (b, c)
h) = forall (f :: * -> *) a b c.
Divise f =>
(a -> (b, c)) -> f b -> f c -> f a
divise x -> (b, c)
h (g ~> f
f g b
x) (h ~> f
g h c
y)

instance Associative ID.Day where
    type NonEmptyBy ID.Day = DivAp1
    type FunctorBy ID.Day = Invariant
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Day f, FunctorBy Day g, FunctorBy Day h) =>
Day f (Day g h) <~> Day (Day f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) ~> t (t f g) h
assoc forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t (t f g) h ~> t f (t g h)
disassoc

    appendNE :: forall (f :: * -> *).
Day (NonEmptyBy Day f) (NonEmptyBy Day f) ~> NonEmptyBy Day f
appendNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall (f :: * -> *).
Day (Chain1 Day f) (Chain1 Day f) ~> Chain1 Day f
appendNEIDay_
    matchNE :: forall (f :: * -> *).
FunctorBy Day f =>
NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1

    consNE :: forall (f :: * -> *). Day f (NonEmptyBy Day f) ~> NonEmptyBy Day f
consNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1
    toNonEmptyBy :: forall (f :: * -> *). Day f f ~> NonEmptyBy Day f
toNonEmptyBy = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
HBifunctor t =>
t f f ~> Chain1 t f
toChain1

appendNEIDay_ :: ID.Day (Chain1 ID.Day f) (Chain1 ID.Day f) ~> Chain1 ID.Day f
appendNEIDay_ :: forall (f :: * -> *).
Day (Chain1 Day f) (Chain1 Day f) ~> Chain1 Day f
appendNEIDay_ (ID.Day Chain1 Day f b
xs Chain1 Day f c
ys b -> c -> x
g x -> (b, c)
f) = case Chain1 Day f b
xs of
  Done1 f b
x              -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day f b
x Chain1 Day f c
ys b -> c -> x
g x -> (b, c)
f)
  More1 (ID.Day f b
z Chain1 Day f c
zs b -> c -> b
j b -> (b, c)
h) -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 forall a b. (a -> b) -> a -> b
$
    forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day f b
z (forall (f :: * -> *).
Day (Chain1 Day f) (Chain1 Day f) ~> Chain1 Day f
appendNEIDay_ (forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (b -> c -> a) -> (a -> (b, c)) -> Day f g a
ID.Day Chain1 Day f c
zs Chain1 Day f c
ys (,) forall a. a -> a
id))
      (\b
a (c
b, c
c) -> b -> c -> x
g (b -> c -> b
j b
a c
b) c
c)
      (forall (p :: * -> * -> *) a b c.
Assoc p =>
p (p a b) c -> p a (p b c)
B.assoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> (b, c)
h forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f)

-- | @since 0.4.0.0
instance Inply f => SemigroupIn ID.Day f where
    biretract :: Day f f ~> f
biretract = forall (f :: * -> *). Inply f => Day f f ~> f
dather
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Day g h ~> f
binterpret = forall (h :: * -> *) (f :: * -> *) (g :: * -> *).
Inply h =>
(f ~> h) -> (g ~> h) -> Day f g ~> h
runDay

instance Associative IN.Night where
    type NonEmptyBy IN.Night = DecAlt1
    type FunctorBy IN.Night = Invariant
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Night f, FunctorBy Night g, FunctorBy Night h) =>
Night f (Night g h) <~> Night (Night f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night f (Night g h) ~> Night (Night f g) h
IN.assoc forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night (Night f g) h ~> Night f (Night g h)
IN.unassoc

    appendNE :: forall (f :: * -> *).
Night (NonEmptyBy Night f) (NonEmptyBy Night f)
~> NonEmptyBy Night f
appendNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall (f :: * -> *).
Night (Chain1 Night f) (Chain1 Night f) ~> Chain1 Night f
appendNEINight_
    matchNE :: forall (f :: * -> *).
FunctorBy Night f =>
NonEmptyBy Night f ~> (f :+: Night f (NonEmptyBy Night f))
matchNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1

    consNE :: forall (f :: * -> *).
Night f (NonEmptyBy Night f) ~> NonEmptyBy Night f
consNE = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1
    toNonEmptyBy :: forall (f :: * -> *). Night f f ~> NonEmptyBy Night f
toNonEmptyBy = coerce :: forall a b. Coercible a b => a -> b
coerce forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
HBifunctor t =>
t f f ~> Chain1 t f
toChain1

appendNEINight_ :: IN.Night (Chain1 IN.Night f) (Chain1 IN.Night f) ~> Chain1 IN.Night f
appendNEINight_ :: forall (f :: * -> *).
Night (Chain1 Night f) (Chain1 Night f) ~> Chain1 Night f
appendNEINight_ (IN.Night Chain1 Night f b1
xs Chain1 Night f c1
ys b1 -> x
f c1 -> x
g x -> Either b1 c1
h) = case Chain1 Night f b1
xs of
  Done1 f b1
x                     -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night f b1
x Chain1 Night f c1
ys b1 -> x
f c1 -> x
g x -> Either b1 c1
h)
  More1 (IN.Night f b1
z Chain1 Night f c1
zs b1 -> b1
j c1 -> b1
k b1 -> Either b1 c1
l) -> forall {k} (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 forall a b. (a -> b) -> a -> b
$
    forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night f b1
z (forall (f :: * -> *).
Night (Chain1 Night f) (Chain1 Night f) ~> Chain1 Night f
appendNEINight_ (forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1
-> b c1
-> (b1 -> c)
-> (c1 -> c)
-> (c -> Either b1 c1)
-> Night a b c
IN.Night Chain1 Night f c1
zs Chain1 Night f c1
ys forall a b. a -> Either a b
Left forall a b. b -> Either a b
Right forall a. a -> a
id))
      (b1 -> x
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. b1 -> b1
j)
      (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (b1 -> x
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. c1 -> b1
k) c1 -> x
g)
      (forall (p :: * -> * -> *) a b c.
Assoc p =>
p (p a b) c -> p a (p b c)
B.assoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b1 -> Either b1 c1
l forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> Either b1 c1
h)

-- | @since 0.4.0.0
instance Inalt f => SemigroupIn IN.Night f where
    biretract :: Night f f ~> f
biretract = forall (f :: * -> *). Inalt f => Night f f ~> f
IN.nerve
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Night g h ~> f
binterpret = forall (h :: * -> *) (f :: * -> *) (g :: * -> *).
Inalt h =>
(f ~> h) -> (g ~> h) -> Night f g ~> h
IN.runNight

-- | @since 0.3.0.0
instance Associative Night where
    type NonEmptyBy Night = Dec1
    type FunctorBy Night = Contravariant
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Night f, FunctorBy Night g, FunctorBy Night h) =>
Night f (Night g h) <~> Night (Night f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night f (Night g h) ~> Night (Night f g) h
N.assoc forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night (Night f g) h ~> Night f (Night g h)
N.unassoc

    appendNE :: forall (f :: * -> *).
Night (NonEmptyBy Night f) (NonEmptyBy Night f)
~> NonEmptyBy Night f
appendNE (Night NonEmptyBy Night f b1
x NonEmptyBy Night f c1
y x -> Either b1 c1
f) = forall (f :: * -> *) a b c.
Decide f =>
(a -> Either b c) -> f b -> f c -> f a
decide x -> Either b1 c1
f NonEmptyBy Night f b1
x NonEmptyBy Night f c1
y
    matchNE :: forall (f :: * -> *).
FunctorBy Night f =>
NonEmptyBy Night f ~> (f :+: Night f (NonEmptyBy Night f))
matchNE (Dec1 x -> Either b1 c
f f b1
x Dec f c
xs) = case Dec f c
xs of
      Lose c -> Void
g -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. a -> a
id (forall a. Void -> a
absurd forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Void
g) forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> Either b1 c
f) f b1
x
      Choose c -> Either b1 c
g f b1
y Dec f c
ys -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall (a :: * -> *) b1 (b :: * -> *) c1 c.
a b1 -> b c1 -> (c -> Either b1 c1) -> Night a b c
Night f b1
x (forall b b1 c (a :: * -> *).
(b -> Either b1 c) -> a b1 -> Dec a c -> Dec1 a b
Dec1 c -> Either b1 c
g f b1
y Dec f c
ys) x -> Either b1 c
f

    consNE :: forall (f :: * -> *).
Night f (NonEmptyBy Night f) ~> NonEmptyBy Night f
consNE (Night f b1
x NonEmptyBy Night f c1
y x -> Either b1 c1
f) = forall b b1 c (a :: * -> *).
(b -> Either b1 c) -> a b1 -> Dec a c -> Dec1 a b
Dec1 x -> Either b1 c1
f f b1
x (forall (f :: * -> *) a. Dec1 f a -> Dec f a
toDec NonEmptyBy Night f c1
y)
    toNonEmptyBy :: forall (f :: * -> *). Night f f ~> NonEmptyBy Night f
toNonEmptyBy (Night f b1
x f c1
y x -> Either b1 c1
f) = forall b b1 c (a :: * -> *).
(b -> Either b1 c) -> a b1 -> Dec a c -> Dec1 a b
Dec1 x -> Either b1 c1
f f b1
x (forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f c1
y)

-- | @since 0.3.0.0
instance Decide f => SemigroupIn Night f where
    biretract :: Night f f ~> f
biretract      (Night f b1
x f c1
y x -> Either b1 c1
f) = forall (f :: * -> *) a b c.
Decide f =>
(a -> Either b c) -> f b -> f c -> f a
decide x -> Either b1 c1
f f b1
x f c1
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Night g h ~> f
binterpret g ~> f
f h ~> f
g (Night g b1
x h c1
y x -> Either b1 c1
h) = forall (f :: * -> *) a b c.
Decide f =>
(a -> Either b c) -> f b -> f c -> f a
decide x -> Either b1 c1
h (g ~> f
f g b1
x) (h ~> f
g h c1
y)

instance Associative (:+:) where
    type NonEmptyBy (:+:) = Step

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy (:+:) f, FunctorBy (:+:) g, FunctorBy (:+:) h) =>
(f :+: (g :+: h)) <~> ((f :+: g) :+: h)
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {f :: k -> *} {g :: k -> *} {g :: k -> *} {p :: k}.
(:+:) f (g :+: g) p -> (:+:) (f :+: g) g p
to_ forall {k} {f :: k -> *} {f :: k -> *} {g :: k -> *} {p :: k}.
(:+:) (f :+: f) g p -> (:+:) f (f :+: g) p
from_
      where
        to_ :: (:+:) f (g :+: g) p -> (:+:) (f :+: g) g p
to_ = \case
          L1 f p
x      -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
x)
          R1 (L1 g p
y) -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 g p
y)
          R1 (R1 g p
z) -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 g p
z
        from_ :: (:+:) (f :+: f) g p -> (:+:) f (f :+: g) p
from_ = \case
          L1 (L1 f p
x) -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
x
          L1 (R1 f p
y) -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
y)
          R1 g p
z      -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 g p
z)

    appendNE :: forall (f :: * -> *).
(NonEmptyBy (:+:) f :+: NonEmptyBy (:+:) f) ~> NonEmptyBy (:+:) f
appendNE = \case
      L1 (Step Natural
i f x
x) -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
i forall a. Num a => a -> a -> a
+ Natural
1) f x
x
      R1 (Step Natural
i f x
y) -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
i forall a. Num a => a -> a -> a
+ Natural
2) f x
y
    matchNE :: forall (f :: * -> *).
FunctorBy (:+:) f =>
NonEmptyBy (:+:) f ~> (f :+: (f :+: NonEmptyBy (:+:) f))
matchNE = forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} (f :: k -> *). Step f ~> (f :+: Step f)
stepDown forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). Step f ~> (f :+: Step f)
stepDown

    consNE :: forall (f :: * -> *).
(f :+: NonEmptyBy (:+:) f) ~> NonEmptyBy (:+:) f
consNE = forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp
    toNonEmptyBy :: forall (f :: * -> *). (f :+: f) ~> NonEmptyBy (:+:) f
toNonEmptyBy = \case
      L1 f x
x -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
1 f x
x
      R1 f x
y -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
2 f x
y

-- | All functors are semigroups in the semigroupoidal category on ':+:'.
instance SemigroupIn (:+:) f where
    biretract :: (f :+: f) ~> f
biretract = \case
      L1 f x
x -> f x
x
      R1 f x
y -> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> (g :+: h) ~> f
binterpret g ~> f
f h ~> f
g = \case
      L1 g x
x -> g ~> f
f g x
x
      R1 h x
y -> h ~> f
g h x
y

instance Associative Sum where
    type NonEmptyBy Sum = Step
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Sum f, FunctorBy Sum g, FunctorBy Sum h) =>
Sum f (Sum g h) <~> Sum (Sum f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {f :: k -> *} {g :: k -> *} {g :: k -> *} {a :: k}.
Sum f (Sum g g) a -> Sum (Sum f g) g a
to_ forall {k} {f :: k -> *} {f :: k -> *} {g :: k -> *} {a :: k}.
Sum (Sum f f) g a -> Sum f (Sum f g) a
from_
      where
        to_ :: Sum f (Sum g g) a -> Sum (Sum f g) g a
to_ = \case
          InL f a
x       -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
x)
          InR (InL g a
y) -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g a
y)
          InR (InR g a
z) -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g a
z
        from_ :: Sum (Sum f f) g a -> Sum f (Sum f g) a
from_ = \case
          InL (InL f a
x) -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
x
          InL (InR f a
y) -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
y)
          InR g a
z       -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g a
z)

    appendNE :: forall (f :: * -> *).
Sum (NonEmptyBy Sum f) (NonEmptyBy Sum f) ~> NonEmptyBy Sum f
appendNE = \case
      InL (Step Natural
i f x
x) -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
i forall a. Num a => a -> a -> a
+ Natural
1) f x
x
      InR (Step Natural
i f x
y) -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
i forall a. Num a => a -> a -> a
+ Natural
2) f x
y
    matchNE :: forall (f :: * -> *).
FunctorBy Sum f =>
NonEmptyBy Sum f ~> (f :+: Sum f (NonEmptyBy Sum f))
matchNE = forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright (forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> f ~> g
viewF forall {k} (f :: k -> *) (g :: k -> *). (f :+: g) <~> Sum f g
sumSum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). Step f ~> (f :+: Step f)
stepDown) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). Step f ~> (f :+: Step f)
stepDown

    consNE :: forall (f :: * -> *). Sum f (NonEmptyBy Sum f) ~> NonEmptyBy Sum f
consNE = forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> g ~> f
reviewF forall {k} (f :: k -> *) (g :: k -> *). (f :+: g) <~> Sum f g
sumSum
    toNonEmptyBy :: forall (f :: * -> *). Sum f f ~> NonEmptyBy Sum f
toNonEmptyBy = \case
      InL f x
x -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
1 f x
x
      InR f x
y -> forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
2 f x
y

-- | All functors are semigroups in the semigroupoidal category on 'Sum'.
instance SemigroupIn Sum f where
    biretract :: Sum f f ~> f
biretract = \case
      InR f x
x -> f x
x
      InL f x
y -> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Sum g h ~> f
binterpret g ~> f
f h ~> f
g = \case
      InL g x
x -> g ~> f
f g x
x
      InR h x
y -> h ~> f
g h x
y

-- | Ideally here 'NonEmptyBy' would be equivalent to 'Data.HBifunctor.Tensor.ListBy',
-- just like for ':+:'. This should be possible if we can write
-- a bijection.  This bijection should be possible in theory --- but it has
-- not yet been implemented.
instance Associative These1 where
    type NonEmptyBy These1 = ComposeT Flagged Steps
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy These1 f, FunctorBy These1 g, FunctorBy These1 h) =>
These1 f (These1 g h) <~> These1 (These1 f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {f :: * -> *} {g :: * -> *} {g :: * -> *} {a}.
These1 f (These1 g g) a -> These1 (These1 f g) g a
to_ forall {f :: * -> *} {f :: * -> *} {g :: * -> *} {a}.
These1 (These1 f f) g a -> These1 f (These1 f g) a
from_
      where
        to_ :: These1 f (These1 g g) a -> These1 (These1 f g) g a
to_ = \case
          This1  f a
x              -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
x  )
          That1    (This1  g a
y  ) -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
y)
          That1    (That1    g a
z) -> forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1               g a
z
          That1    (These1 g a
y g a
z) -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
y) g a
z
          These1 f a
x (This1  g a
y  ) -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x g a
y)
          These1 f a
x (That1    g a
z) -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
x  ) g a
z
          These1 f a
x (These1 g a
y g a
z) -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x g a
y) g a
z
        from_ :: These1 (These1 f f) g a -> These1 f (These1 f g) a
from_ = \case
          This1  (This1  f a
x  )   -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
x
          This1  (That1    f a
y)   -> forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
y  )
          This1  (These1 f a
x f a
y)   -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
y  )
          That1               g a
z -> forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
z)
          These1 (This1  f a
x  ) g a
z -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
z)
          These1 (That1    f a
y) g a
z -> forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
y g a
z)
          These1 (These1 f a
x f a
y) g a
z -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
y g a
z)

    appendNE :: forall (f :: * -> *).
These1 (NonEmptyBy These1 f) (NonEmptyBy These1 f)
~> NonEmptyBy These1 f
appendNE These1 (NonEmptyBy These1 f) (NonEmptyBy These1 f) x
s = forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall a b. (a -> b) -> a -> b
$ case These1 (NonEmptyBy These1 f) (NonEmptyBy These1 f) x
s of
        This1  (ComposeT (Flagged Bool
_ Steps f x
q))                       ->
          forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True Steps f x
q
        That1                           (ComposeT (Flagged Bool
b Steps f x
q)) ->
          forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
b        (forall (f :: * -> *). These1 f (Steps f) ~> Steps f
stepsUp (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1 Steps f x
q))
        These1 (ComposeT (Flagged Bool
a Steps f x
q)) (ComposeT (Flagged Bool
b Steps f x
r)) ->
          forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged (Bool
a Bool -> Bool -> Bool
|| Bool
b) (Steps f x
q forall a. Semigroup a => a -> a -> a
<> Steps f x
r)
    matchNE :: forall (f :: * -> *).
FunctorBy These1 f =>
NonEmptyBy These1 f ~> (f :+: These1 f (NonEmptyBy These1 f))
matchNE (ComposeT (Flagged Bool
isImpure Steps f x
q)) = case forall (f :: * -> *). Steps f ~> These1 f (Steps f)
stepsDown Steps f x
q of
      This1  f x
x
        | Bool
isImpure  -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1 f x
x
        | Bool
otherwise -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
      That1    Steps f x
y    -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall a b. (a -> b) -> a -> b
$ forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
isImpure Steps f x
y
      These1 f x
x Steps f x
y    -> forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f x
x forall b c a. (b -> c) -> (a -> b) -> a -> c
.  forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall a b. (a -> b) -> a -> b
$ forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
isImpure Steps f x
y

    consNE :: forall (f :: * -> *).
These1 f (NonEmptyBy These1 f) ~> NonEmptyBy These1 f
consNE These1 f (NonEmptyBy These1 f) x
s = forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall a b. (a -> b) -> a -> b
$ case These1 f (NonEmptyBy These1 f) x
s of
      This1  f x
x                          -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True (forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f x
x)
      That1    (ComposeT (Flagged Bool
b Steps f x
y)) -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
b    (forall (f :: * -> *). These1 f (Steps f) ~> Steps f
stepsUp (forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    Steps f x
y))
      These1 f x
x (ComposeT (Flagged Bool
b Steps f x
y)) -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
b    (forall (f :: * -> *). These1 f (Steps f) ~> Steps f
stepsUp (forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f x
x Steps f x
y))
    toNonEmptyBy :: forall (f :: * -> *). These1 f f ~> NonEmptyBy These1 f
toNonEmptyBy  These1 f f x
s = forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall a b. (a -> b) -> a -> b
$ case These1 f f x
s of
      This1  f x
x   -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NEMap Natural (f a) -> Steps f a
Steps forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> NEMap k a
NEM.singleton Natural
0 f x
x
      That1    f x
y -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NEMap Natural (f a) -> Steps f a
Steps forall a b. (a -> b) -> a -> b
$ forall k a. k -> a -> NEMap k a
NEM.singleton Natural
1 f x
y
      These1 f x
x f x
y -> forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
False forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NEMap Natural (f a) -> Steps f a
Steps forall a b. (a -> b) -> a -> b
$ forall k a. NonEmpty (k, a) -> NEMap k a
NEM.fromDistinctAscList forall a b. (a -> b) -> a -> b
$ (Natural
0, f x
x) forall a. a -> [a] -> NonEmpty a
:| [(Natural
1, f x
y)]

instance Alt f => SemigroupIn These1 f where
    biretract :: These1 f f ~> f
biretract = \case
      This1  f x
x   -> f x
x
      That1    f x
y -> f x
y
      These1 f x
x f x
y -> f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> These1 g h ~> f
binterpret g ~> f
f h ~> f
g = \case
      This1  g x
x   -> g ~> f
f g x
x
      That1    h x
y -> h ~> f
g h x
y
      These1 g x
x h x
y -> g ~> f
f g x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> h ~> f
g h x
y

instance Associative Void3 where
    type NonEmptyBy Void3 = IdentityT
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Void3 f, FunctorBy Void3 g, FunctorBy Void3 h) =>
Void3 f (Void3 g h) <~> Void3 (Void3 f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF coerce :: forall a b. Coercible a b => a -> b
coerce coerce :: forall a b. Coercible a b => a -> b
coerce

    appendNE :: forall (f :: * -> *).
Void3 (NonEmptyBy Void3 f) (NonEmptyBy Void3 f)
~> NonEmptyBy Void3 f
appendNE = \case {}
    matchNE :: forall (f :: * -> *).
FunctorBy Void3 f =>
NonEmptyBy Void3 f ~> (f :+: Void3 f (NonEmptyBy Void3 f))
matchNE  = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT

    consNE :: forall (f :: * -> *).
Void3 f (NonEmptyBy Void3 f) ~> NonEmptyBy Void3 f
consNE = \case {}
    toNonEmptyBy :: forall (f :: * -> *). Void3 f f ~> NonEmptyBy Void3 f
toNonEmptyBy   = \case {}

-- | All functors are semigroups in the semigroupoidal category on 'Void3'.
instance SemigroupIn Void3 f where
    biretract :: Void3 f f ~> f
biretract = \case {}
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Void3 g h ~> f
binterpret g ~> f
_ h ~> f
_ = \case {}

instance Associative Comp where
    type NonEmptyBy Comp = Free1
    type FunctorBy Comp = Functor

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Comp f, FunctorBy Comp g, FunctorBy Comp h) =>
Comp f (Comp g h) <~> Comp (Comp f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF forall {k} {g :: * -> *} {f :: * -> *} {g :: k -> *} {a :: k}.
Functor g =>
Comp f (Comp g g) a -> Comp (Comp f g) g a
to_ forall {k} {f :: * -> *} {g :: * -> *} {g :: k -> *} {a :: k}.
Comp (Comp f g) g a -> Comp f (Comp g g) a
from_
      where
        to_ :: Comp f (Comp g g) a -> Comp (Comp f g) g a
to_   (f x
x :>>= x -> Comp g g a
y) = (f x
x forall {k} (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= (forall {k} (f :: * -> *) (g :: k -> *) (a :: k).
Functor f =>
Comp f g a -> f (g a)
unComp forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> Comp g g a
y)) forall {k} (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= forall a. a -> a
id
        from_ :: Comp (Comp f g) g a -> Comp f (Comp g g) a
from_ ((f x
x :>>= x -> g x
y) :>>= x -> g a
z) = f x
x forall {k} (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= ((forall {k} (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= x -> g a
z) forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> g x
y)

    appendNE :: forall (f :: * -> *).
Comp (NonEmptyBy Comp f) (NonEmptyBy Comp f) ~> NonEmptyBy Comp f
appendNE (NonEmptyBy Comp f x
x :>>= x -> NonEmptyBy Comp f x
y) = NonEmptyBy Comp f x
x forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- x -> NonEmptyBy Comp f x
y
    matchNE :: forall (f :: * -> *).
FunctorBy Comp f =>
NonEmptyBy Comp f ~> (f :+: Comp f (NonEmptyBy Comp f))
matchNE = forall (f :: * -> *).
Functor f =>
Free1 f ~> (f :+: Comp f (Free1 f))
matchFree1

    consNE :: forall (f :: * -> *).
Comp f (NonEmptyBy Comp f) ~> NonEmptyBy Comp f
consNE (f x
x :>>= x -> NonEmptyBy Comp f x
y) = forall (f :: * -> *). f ~> Free1 f
liftFree1 f x
x forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- x -> NonEmptyBy Comp f x
y
    toNonEmptyBy :: forall (f :: * -> *). Comp f f ~> NonEmptyBy Comp f
toNonEmptyBy   (f x
x :>>= x -> f x
g) = forall (f :: * -> *). f ~> Free1 f
liftFree1 f x
x forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> f x
g

-- | Instances of 'Bind' are semigroups in the semigroupoidal category on
-- 'Comp'.
instance Bind f => SemigroupIn Comp f where
    biretract :: Comp f f ~> f
biretract      (f x
x :>>= x -> f x
y) = f x
x forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- x -> f x
y
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Comp g h ~> f
binterpret g ~> f
f h ~> f
g (g x
x :>>= x -> h x
y) = g ~> f
f g x
x forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- (h ~> f
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> h x
y)

---- data TC f a = TCA (f a) Bool
----             | TCB (Maybe (f a)) (TC f a)
--                -- sparse, non-empty list
--                -- and the last item has a Bool
--                -- aka sparse non-empty list tagged with a bool

instance Associative Joker where
    type NonEmptyBy Joker = Flagged
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy Joker f, FunctorBy Joker g, FunctorBy Joker h) =>
Joker f (Joker g h) <~> Joker (Joker f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker)
                       (forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker)
    appendNE :: forall (f :: * -> *).
Joker (NonEmptyBy Joker f) (NonEmptyBy Joker f)
~> NonEmptyBy Joker f
appendNE (Joker (Flagged Bool
_ f x
x)) = forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True f x
x
    matchNE :: forall (f :: * -> *).
FunctorBy Joker f =>
NonEmptyBy Joker f ~> (f :+: Joker f (NonEmptyBy Joker f))
matchNE (Flagged Bool
False f x
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
    matchNE (Flagged Bool
True  f x
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall {k} {k1} (g :: k -> *) (a :: k1) (b :: k).
g b -> Joker g a b
Joker f x
x

instance SemigroupIn Joker f where
    biretract :: Joker f f ~> f
biretract = forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> Joker g h ~> f
binterpret g ~> f
f h ~> f
_ = g ~> f
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (g :: k1 -> *) (a :: k2) (b :: k1).
Joker g a b -> g b
runJoker

instance Associative LeftF where
    type NonEmptyBy LeftF = Flagged
    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy LeftF f, FunctorBy LeftF g, FunctorBy LeftF h) =>
LeftF f (LeftF g h) <~> LeftF (LeftF f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall {k} {k1} (f :: k -> *) (g :: k1) (a :: k).
f a -> LeftF f g a
LeftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (f :: k -> *) (g :: k1) (a :: k).
f a -> LeftF f g a
LeftF    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF)
                       (forall {k} {k1} (f :: k -> *) (g :: k1) (a :: k).
f a -> LeftF f g a
LeftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF)

    appendNE :: forall (f :: * -> *).
LeftF (NonEmptyBy LeftF f) (NonEmptyBy LeftF f)
~> NonEmptyBy LeftF f
appendNE = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind (forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF
    matchNE :: forall (f :: * -> *).
FunctorBy LeftF f =>
NonEmptyBy LeftF f ~> (f :+: LeftF f (NonEmptyBy LeftF f))
matchNE (Flagged Bool
False f x
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
    matchNE (Flagged Bool
True  f x
x) = forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall a b. (a -> b) -> a -> b
$ forall {k} {k1} (f :: k -> *) (g :: k1) (a :: k).
f a -> LeftF f g a
LeftF f x
x

    consNE :: forall (f :: * -> *).
LeftF f (NonEmptyBy LeftF f) ~> NonEmptyBy LeftF f
consNE = forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF
    toNonEmptyBy :: forall (f :: * -> *). LeftF f f ~> NonEmptyBy LeftF f
toNonEmptyBy   = forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF

instance SemigroupIn LeftF f where
    biretract :: LeftF f f ~> f
biretract      = forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> LeftF g h ~> f
binterpret g ~> f
f h ~> f
_ = g ~> f
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2) (a :: k1).
LeftF f g a -> f a
runLeftF

instance Associative RightF where
    type NonEmptyBy RightF = Step

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy RightF f, FunctorBy RightF g, FunctorBy RightF h) =>
RightF f (RightF g h) <~> RightF (RightF f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall {k} {k1} (f :: k) (g :: k1 -> *) (a :: k1).
g a -> RightF f g a
RightF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF)
                       (forall {k} {k1} (f :: k) (g :: k1 -> *) (a :: k1).
g a -> RightF f g a
RightF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (f :: k) (g :: k1 -> *) (a :: k1).
g a -> RightF f g a
RightF    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF)

    appendNE :: forall (f :: * -> *).
RightF (NonEmptyBy RightF f) (NonEmptyBy RightF f)
~> NonEmptyBy RightF f
appendNE = forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF
    matchNE :: forall (f :: * -> *).
FunctorBy RightF f =>
NonEmptyBy RightF f ~> (f :+: RightF f (NonEmptyBy RightF f))
matchNE  = forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} {k1} (f :: k) (g :: k1 -> *) (a :: k1).
g a -> RightF f g a
RightF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *). Step f ~> (f :+: Step f)
stepDown

    consNE :: forall (f :: * -> *).
RightF f (NonEmptyBy RightF f) ~> NonEmptyBy RightF f
consNE   = forall {k} (f :: k -> *). (f :+: Step f) ~> Step f
stepUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF
    toNonEmptyBy :: forall (f :: * -> *). RightF f f ~> NonEmptyBy RightF f
toNonEmptyBy     = forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF

instance SemigroupIn RightF f where
    biretract :: RightF f f ~> f
biretract      = forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> f) -> (h ~> f) -> RightF g h ~> f
binterpret g ~> f
_ h ~> f
g = h ~> f
g forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1) (g :: k2 -> *) (a :: k2).
RightF f g a -> g a
runRightF

-- | A newtype wrapper meant to be used to define polymorphic 'SemigroupIn'
-- instances.  See documentation for 'SemigroupIn' for more information.
--
-- Please do not ever define an instance of 'SemigroupIn' "naked" on the
-- second parameter:
--
-- @
-- instance SemigroupIn (WrapHBF t) f
-- @
--
-- As that would globally ruin everything using 'WrapHBF'.
newtype WrapHBF t f g a = WrapHBF { forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF :: t f g a }
  deriving (Int -> WrapHBF t f g a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
Int -> WrapHBF t f g a -> ShowS
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
[WrapHBF t f g a] -> ShowS
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
WrapHBF t f g a -> String
showList :: [WrapHBF t f g a] -> ShowS
$cshowList :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
[WrapHBF t f g a] -> ShowS
show :: WrapHBF t f g a -> String
$cshow :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
WrapHBF t f g a -> String
showsPrec :: Int -> WrapHBF t f g a -> ShowS
$cshowsPrec :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Show (t f g a) =>
Int -> WrapHBF t f g a -> ShowS
Show, ReadPrec [WrapHBF t f g a]
ReadPrec (WrapHBF t f g a)
ReadS [WrapHBF t f g a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadPrec [WrapHBF t f g a]
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadPrec (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
Int -> ReadS (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadS [WrapHBF t f g a]
readListPrec :: ReadPrec [WrapHBF t f g a]
$creadListPrec :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadPrec [WrapHBF t f g a]
readPrec :: ReadPrec (WrapHBF t f g a)
$creadPrec :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadPrec (WrapHBF t f g a)
readList :: ReadS [WrapHBF t f g a]
$creadList :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
ReadS [WrapHBF t f g a]
readsPrec :: Int -> ReadS (WrapHBF t f g a)
$creadsPrec :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Read (t f g a) =>
Int -> ReadS (WrapHBF t f g a)
Read, WrapHBF t f g a -> WrapHBF t f g a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Eq (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
/= :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c/= :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Eq (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
== :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c== :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Eq (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
Eq, WrapHBF t f g a -> WrapHBF t f g a -> Bool
WrapHBF t f g a -> WrapHBF t f g a -> Ordering
WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
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 {k} {k} {k} {t :: k -> k -> k -> *} {f :: k} {g :: k}
       {a :: k}.
Ord (t f g a) =>
Eq (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Ordering
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
min :: WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
$cmin :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
max :: WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
$cmax :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> WrapHBF t f g a
>= :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c>= :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
> :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c> :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
<= :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c<= :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
< :: WrapHBF t f g a -> WrapHBF t f g a -> Bool
$c< :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Bool
compare :: WrapHBF t f g a -> WrapHBF t f g a -> Ordering
$ccompare :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
Ord (t f g a) =>
WrapHBF t f g a -> WrapHBF t f g a -> Ordering
Ord, forall a b. a -> WrapHBF t f g b -> WrapHBF t f g a
forall a b. (a -> b) -> WrapHBF t f g a -> WrapHBF t f g b
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Functor (t f g) =>
a -> WrapHBF t f g b -> WrapHBF t f g a
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Functor (t f g) =>
(a -> b) -> WrapHBF t f g a -> WrapHBF t f g b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> WrapHBF t f g b -> WrapHBF t f g a
$c<$ :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Functor (t f g) =>
a -> WrapHBF t f g b -> WrapHBF t f g a
fmap :: forall a b. (a -> b) -> WrapHBF t f g a -> WrapHBF t f g b
$cfmap :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Functor (t f g) =>
(a -> b) -> WrapHBF t f g a -> WrapHBF t f g b
Functor, forall a. Eq a => a -> WrapHBF t f g a -> Bool
forall a. Num a => WrapHBF t f g a -> a
forall a. Ord a => WrapHBF t f g a -> a
forall m. Monoid m => WrapHBF t f g m -> m
forall a. WrapHBF t f g a -> Bool
forall a. WrapHBF t f g a -> Int
forall a. WrapHBF t f g a -> [a]
forall a. (a -> a -> a) -> WrapHBF t f g a -> a
forall m a. Monoid m => (a -> m) -> WrapHBF t f g a -> m
forall b a. (b -> a -> b) -> b -> WrapHBF t f g a -> b
forall a b. (a -> b -> b) -> b -> WrapHBF t f g a -> b
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Eq a) =>
a -> WrapHBF t f g a -> Bool
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Num a) =>
WrapHBF t f g a -> a
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Ord a) =>
WrapHBF t f g a -> a
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) m.
(Foldable (t f g), Monoid m) =>
WrapHBF t f g m -> m
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> Bool
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> Int
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> [a]
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
(a -> a -> a) -> WrapHBF t f g a -> a
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) m a.
(Foldable (t f g), Monoid m) =>
(a -> m) -> WrapHBF t f g a -> m
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) b a.
Foldable (t f g) =>
(b -> a -> b) -> b -> WrapHBF t f g a -> b
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Foldable (t f g) =>
(a -> b -> b) -> b -> WrapHBF t f g 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
product :: forall a. Num a => WrapHBF t f g a -> a
$cproduct :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Num a) =>
WrapHBF t f g a -> a
sum :: forall a. Num a => WrapHBF t f g a -> a
$csum :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Num a) =>
WrapHBF t f g a -> a
minimum :: forall a. Ord a => WrapHBF t f g a -> a
$cminimum :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Ord a) =>
WrapHBF t f g a -> a
maximum :: forall a. Ord a => WrapHBF t f g a -> a
$cmaximum :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Ord a) =>
WrapHBF t f g a -> a
elem :: forall a. Eq a => a -> WrapHBF t f g a -> Bool
$celem :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
(Foldable (t f g), Eq a) =>
a -> WrapHBF t f g a -> Bool
length :: forall a. WrapHBF t f g a -> Int
$clength :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> Int
null :: forall a. WrapHBF t f g a -> Bool
$cnull :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> Bool
toList :: forall a. WrapHBF t f g a -> [a]
$ctoList :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
WrapHBF t f g a -> [a]
foldl1 :: forall a. (a -> a -> a) -> WrapHBF t f g a -> a
$cfoldl1 :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
(a -> a -> a) -> WrapHBF t f g a -> a
foldr1 :: forall a. (a -> a -> a) -> WrapHBF t f g a -> a
$cfoldr1 :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a.
Foldable (t f g) =>
(a -> a -> a) -> WrapHBF t f g a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> WrapHBF t f g a -> b
$cfoldl' :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) b a.
Foldable (t f g) =>
(b -> a -> b) -> b -> WrapHBF t f g a -> b
foldl :: forall b a. (b -> a -> b) -> b -> WrapHBF t f g a -> b
$cfoldl :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) b a.
Foldable (t f g) =>
(b -> a -> b) -> b -> WrapHBF t f g a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> WrapHBF t f g a -> b
$cfoldr' :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Foldable (t f g) =>
(a -> b -> b) -> b -> WrapHBF t f g a -> b
foldr :: forall a b. (a -> b -> b) -> b -> WrapHBF t f g a -> b
$cfoldr :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) a b.
Foldable (t f g) =>
(a -> b -> b) -> b -> WrapHBF t f g a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> WrapHBF t f g a -> m
$cfoldMap' :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) m a.
(Foldable (t f g), Monoid m) =>
(a -> m) -> WrapHBF t f g a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> WrapHBF t f g a -> m
$cfoldMap :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) m a.
(Foldable (t f g), Monoid m) =>
(a -> m) -> WrapHBF t f g a -> m
fold :: forall m. Monoid m => WrapHBF t f g m -> m
$cfold :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) m.
(Foldable (t f g), Monoid m) =>
WrapHBF t f g m -> m
Foldable, forall {k} {k} {t :: k -> k -> * -> *} {f :: k} {g :: k}.
Traversable (t f g) =>
Functor (WrapHBF t f g)
forall {k} {k} {t :: k -> k -> * -> *} {f :: k} {g :: k}.
Traversable (t f g) =>
Foldable (WrapHBF t f g)
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (m :: * -> *)
       a.
(Traversable (t f g), Monad m) =>
WrapHBF t f g (m a) -> m (WrapHBF t f g a)
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (f :: * -> *)
       a.
(Traversable (t f g), Applicative f) =>
WrapHBF t f g (f a) -> f (WrapHBF t f g a)
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (m :: * -> *)
       a b.
(Traversable (t f g), Monad m) =>
(a -> m b) -> WrapHBF t f g a -> m (WrapHBF t f g b)
forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (f :: * -> *)
       a b.
(Traversable (t f g), Applicative f) =>
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
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 (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
sequence :: forall (m :: * -> *) a.
Monad m =>
WrapHBF t f g (m a) -> m (WrapHBF t f g a)
$csequence :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (m :: * -> *)
       a.
(Traversable (t f g), Monad m) =>
WrapHBF t f g (m a) -> m (WrapHBF t f g a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrapHBF t f g a -> m (WrapHBF t f g b)
$cmapM :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (m :: * -> *)
       a b.
(Traversable (t f g), Monad m) =>
(a -> m b) -> WrapHBF t f g a -> m (WrapHBF t f g b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
WrapHBF t f g (f a) -> f (WrapHBF t f g a)
$csequenceA :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (f :: * -> *)
       a.
(Traversable (t f g), Applicative f) =>
WrapHBF t f g (f a) -> f (WrapHBF t f g a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
$ctraverse :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k) (f :: * -> *)
       a b.
(Traversable (t f g), Applicative f) =>
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
Traversable, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) x.
Rep (WrapHBF t f g a) x -> WrapHBF t f g a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) x.
WrapHBF t f g a -> Rep (WrapHBF t f g a) x
$cto :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) x.
Rep (WrapHBF t f g a) x -> WrapHBF t f g a
$cfrom :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) x.
WrapHBF t f g a -> Rep (WrapHBF t f g a) x
Generic, WrapHBF t f g a -> DataType
WrapHBF t f g a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall {k} {k} {k} {t :: k -> k -> k -> *} {f :: k} {g :: k}
       {a :: k}.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
Typeable (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
WrapHBF t f g a -> DataType
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
WrapHBF t f g a -> Constr
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall b. Data b => b -> b) -> WrapHBF t f g a -> WrapHBF t f g a
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) u.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
Int -> (forall d. Data d => d -> u) -> WrapHBF t f g a -> u
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) u.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall d. Data d => d -> u) -> WrapHBF t f g a -> [u]
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) r
       r'.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) r
       r'.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (m :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Monad m) =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (m :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WrapHBF t f g a -> c (WrapHBF t f g a)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (WrapHBF t f g a))
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (WrapHBF t f g a))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WrapHBF t f g a -> c (WrapHBF t f g a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
$cgmapMo :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (m :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
$cgmapMp :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (m :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), MonadPlus m) =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
$cgmapM :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (m :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Monad m) =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> WrapHBF t f g a -> u
$cgmapQi :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) u.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
Int -> (forall d. Data d => d -> u) -> WrapHBF t f g a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> WrapHBF t f g a -> [u]
$cgmapQ :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) u.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall d. Data d => d -> u) -> WrapHBF t f g a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
$cgmapQr :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) r
       r'.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
$cgmapQl :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k) r
       r'.
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
gmapT :: (forall b. Data b => b -> b) -> WrapHBF t f g a -> WrapHBF t f g a
$cgmapT :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall b. Data b => b -> b) -> WrapHBF t f g a -> WrapHBF t f g a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (WrapHBF t f g a))
$cdataCast2 :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (WrapHBF t f g a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (WrapHBF t f g a))
$cdataCast1 :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (WrapHBF t f g a))
dataTypeOf :: WrapHBF t f g a -> DataType
$cdataTypeOf :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
WrapHBF t f g a -> DataType
toConstr :: WrapHBF t f g a -> Constr
$ctoConstr :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
WrapHBF t f g a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a)
$cgunfold :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WrapHBF t f g a -> c (WrapHBF t f g a)
$cgfoldl :: forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k)
       (c :: * -> *).
(Typeable f, Typeable g, Typeable a, Typeable t, Typeable k,
 Typeable k, Typeable k, Data (t f g a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> WrapHBF t f g a -> c (WrapHBF t f g a)
Data)

instance Show1 (t f g) => Show1 (WrapHBF t f g) where
    liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> WrapHBF t f g a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d (WrapHBF t f g a
x) = forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"WrapHBF" Int
d t f g a
x

instance Eq1 (t f g) => Eq1 (WrapHBF t f g) where
    liftEq :: forall a b.
(a -> b -> Bool) -> WrapHBF t f g a -> WrapHBF t f g b -> Bool
liftEq a -> b -> Bool
eq (WrapHBF t f g a
x) (WrapHBF t f g b
y) = forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq t f g a
x t f g b
y

instance Ord1 (t f g) => Ord1 (WrapHBF t f g) where
    liftCompare :: forall a b.
(a -> b -> Ordering)
-> WrapHBF t f g a -> WrapHBF t f g b -> Ordering
liftCompare a -> b -> Ordering
c (WrapHBF t f g a
x) (WrapHBF t f g b
y) = forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c t f g a
x t f g b
y

instance HBifunctor t => HBifunctor (WrapHBF t) where
    hbimap :: forall (f :: k -> *) (j :: k -> *) (g :: k -> *) (l :: k -> *).
(f ~> j) -> (g ~> l) -> WrapHBF t f g ~> WrapHBF t j l
hbimap f ~> j
f g ~> l
g (WrapHBF t f g x
x) = forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *) (l :: k -> *).
HBifunctor t =>
(f ~> j) -> (g ~> l) -> t f g ~> t j l
hbimap f ~> j
f g ~> l
g t f g x
x)
    hleft :: forall (f :: k -> *) (j :: k -> *) (g :: k -> *).
(f ~> j) -> WrapHBF t f g ~> WrapHBF t j g
hleft f ~> j
f (WrapHBF t f g x
x) = forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft f ~> j
f t f g x
x)
    hright :: forall (g :: k -> *) (l :: k -> *) (f :: k -> *).
(g ~> l) -> WrapHBF t f g ~> WrapHBF t f l
hright g ~> l
g (WrapHBF t f g x
x) = forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright g ~> l
g t f g x
x)

deriving via (WrappedHBifunctor (WrapHBF t) f)
    instance HBifunctor t => HFunctor (WrapHBF t f)

instance Associative t => Associative (WrapHBF t) where
    type NonEmptyBy (WrapHBF t) = NonEmptyBy t
    type FunctorBy (WrapHBF t) = FunctorBy t

    associating :: forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(FunctorBy (WrapHBF t) f, FunctorBy (WrapHBF t) g,
 FunctorBy (WrapHBF t) h) =>
WrapHBF t f (WrapHBF t g h) <~> WrapHBF t (WrapHBF t f g) h
associating = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF) (forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF)
                forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) <~> t (t f g) h
associating @t
                forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF) (forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF)

    appendNE :: forall (f :: * -> *).
WrapHBF t (NonEmptyBy (WrapHBF t) f) (NonEmptyBy (WrapHBF t) f)
~> NonEmptyBy (WrapHBF t) f
appendNE     = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF
    matchNE :: forall (f :: * -> *).
FunctorBy (WrapHBF t) f =>
NonEmptyBy (WrapHBF t) f
~> (f :+: WrapHBF t f (NonEmptyBy (WrapHBF t) f))
matchNE      = forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE
    consNE :: forall (f :: * -> *).
WrapHBF t f (NonEmptyBy (WrapHBF t) f) ~> NonEmptyBy (WrapHBF t) f
consNE       = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF
    toNonEmptyBy :: forall (f :: * -> *). WrapHBF t f f ~> NonEmptyBy (WrapHBF t) f
toNonEmptyBy = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF

-- | Any @'NonEmptyBy' t f@ is a @'SemigroupIn' t@ if we have
-- @'Associative' t@. This newtype wrapper witnesses that fact.  We require
-- a newtype wrapper to avoid overlapping instances.
newtype WrapNE t f a = WrapNE { forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
WrapNE t f a -> NonEmptyBy t f a
unwrapNE :: NonEmptyBy t f a }

instance Functor (NonEmptyBy t f) => Functor (WrapNE t f) where
    fmap :: forall a b. (a -> b) -> WrapNE t f a -> WrapNE t f b
fmap a -> b
f (WrapNE NonEmptyBy t f a
x) = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f NonEmptyBy t f a
x)

instance Contravariant (NonEmptyBy t f) => Contravariant (WrapNE t f) where
    contramap :: forall a' a. (a' -> a) -> WrapNE t f a -> WrapNE t f a'
contramap a' -> a
f (WrapNE NonEmptyBy t f a
x) = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f NonEmptyBy t f a
x)

instance Invariant (NonEmptyBy t f) => Invariant (WrapNE t f) where
    invmap :: forall a b. (a -> b) -> (b -> a) -> WrapNE t f a -> WrapNE t f b
invmap a -> b
f b -> a
g (WrapNE NonEmptyBy t f a
x) = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g NonEmptyBy t f a
x)

instance (Associative t, FunctorBy t f, FunctorBy t (WrapNE t f)) => SemigroupIn (WrapHBF t) (WrapNE t f) where
    biretract :: WrapHBF t (WrapNE t f) (WrapNE t f) ~> WrapNE t f
biretract = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *) (l :: k -> *).
HBifunctor t =>
(f ~> j) -> (g ~> l) -> t f g ~> t j l
hbimap forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
WrapNE t f a -> NonEmptyBy t f a
unwrapNE forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
WrapNE t f a -> NonEmptyBy t f a
unwrapNE forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k} {k} (t :: k -> k -> k -> *) (f :: k) (g :: k)
       (a :: k).
WrapHBF t f g a -> t f g a
unwrapHBF
    binterpret :: forall (g :: * -> *) (h :: * -> *).
(g ~> WrapNE t f)
-> (h ~> WrapNE t f) -> WrapHBF t g h ~> WrapNE t f
binterpret g ~> WrapNE t f
f h ~> WrapNE t f
g = forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
t f f ~> f
biretract forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *) (l :: k -> *).
HBifunctor t =>
(f ~> j) -> (g ~> l) -> t f g ~> t j l
hbimap g ~> WrapNE t f
f h ~> WrapNE t f
g