{-# 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 = t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE (t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (t f (NonEmptyBy t f) x
    -> t (NonEmptyBy t f) (NonEmptyBy t f) x)
-> t f (NonEmptyBy t f) x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> NonEmptyBy t f)
-> t f (NonEmptyBy t f) ~> t (NonEmptyBy t f) (NonEmptyBy t f)
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft f ~> NonEmptyBy t f
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 = t f (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE (t f (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (t f f x -> t f (NonEmptyBy t f) x)
-> t f f x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> NonEmptyBy t f) -> t f f ~> t f (NonEmptyBy t f)
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright f ~> NonEmptyBy t f
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 :: t f (t g h) ~> t (t f g) h
assoc = (t f (t g h) <~> t (t f g) h) -> t f (t g h) ~> t (t f g) h
forall k (f :: k -> *) (g :: k -> *). (f <~> g) -> f ~> g
viewF t f (t g h) <~> t (t f g) h
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 :: t (t f g) h ~> t f (t g h)
disassoc = (t f (t g h) <~> t (t f g) h) -> t (t f g) h ~> t f (t g h)
forall k (f :: k -> *) (g :: k -> *). (f <~> g) -> g ~> f
reviewF t f (t g h) <~> t (t f g) h
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 = NonEmptyBy t f x -> f x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Interpret t f =>
t f ~> f
retract (NonEmptyBy t f x -> f x)
-> (t f f x -> NonEmptyBy t f x) -> t f f x -> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t f (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE (t f (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (t f f x -> t f (NonEmptyBy t f) x)
-> t f f x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> NonEmptyBy t f) -> t f f ~> t f (NonEmptyBy t f)
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright f ~> NonEmptyBy t f
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 = NonEmptyBy t f x -> f x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Interpret t f =>
t f ~> f
retract (NonEmptyBy t f x -> f x)
-> (t g h x -> NonEmptyBy t f x) -> t g h x -> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t f f x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy (t f f x -> NonEmptyBy t f x)
-> (t g h x -> t f f x) -> t g h x -> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g ~> f) -> (h ~> f) -> t g h ~> t f f
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 :: NonEmptyBy t f ~> f
retractNE = (forall a. a -> a
forall x. f x -> f x
id (forall x. f x -> f x)
-> (t f (NonEmptyBy t f) ~> f) -> (f :+: t f (NonEmptyBy t f)) ~> f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (h :: * -> *)
       (f :: * -> *) (g :: * -> *).
SemigroupIn t h =>
(f ~> h) -> (g ~> h) -> t f g ~> h
!*! forall (f :: * -> *). SemigroupIn t f => t f f ~> f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
t f f ~> f
biretract @t (t f f x -> f x)
-> (t f (NonEmptyBy t f) x -> t f f x)
-> t f (NonEmptyBy t f) x
-> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NonEmptyBy t f ~> f) -> t f (NonEmptyBy t f) ~> t f f
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 :: * -> *). SemigroupIn t f => NonEmptyBy t f ~> f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
NonEmptyBy t f ~> f
retractNE @t))
          ((:+:) f (t f (NonEmptyBy t f)) x -> f x)
-> (NonEmptyBy t f x -> (:+:) f (t f (NonEmptyBy t f)) x)
-> NonEmptyBy t f x
-> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
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 :: (g ~> f) -> NonEmptyBy t g ~> f
interpretNE g ~> f
f = forall (f :: * -> *). SemigroupIn t f => NonEmptyBy t f ~> f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
NonEmptyBy t f ~> f
retractNE @t (NonEmptyBy t f x -> f x)
-> (NonEmptyBy t g x -> NonEmptyBy t f x)
-> NonEmptyBy t g x
-> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g ~> f) -> NonEmptyBy t g ~> NonEmptyBy t f
forall k k (t :: (k -> *) -> k -> *) (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 :: NonEmptyBy t f <~> (f :+: t f (NonEmptyBy t f))
matchingNE = (NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f)))
-> ((f :+: t f (NonEmptyBy t f)) ~> NonEmptyBy t f)
-> NonEmptyBy t f <~> (f :+: t f (NonEmptyBy t f))
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE (forall x. f x -> NonEmptyBy t f x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject (forall x. f x -> NonEmptyBy t f x)
-> (t f (NonEmptyBy t f) ~> NonEmptyBy t f)
-> (f :+: t f (NonEmptyBy t f)) ~> NonEmptyBy t f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (h :: * -> *)
       (f :: * -> *) (g :: * -> *).
SemigroupIn t h =>
(f ~> h) -> (g ~> h) -> t f g ~> h
!*! t f (NonEmptyBy t f) ~> NonEmptyBy t f
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 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 = AltConst b a -> b
forall w k (a :: k). AltConst w a -> w
getAltConst (AltConst b a -> b) -> (t f g a -> AltConst b a) -> t f g a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> AltConst b) -> (g ~> AltConst b) -> t f g ~> AltConst b
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
SemigroupIn t f =>
(g ~> f) -> (h ~> f) -> t g h ~> f
binterpret (b -> AltConst b x
forall k w (a :: k). w -> AltConst w a
AltConst (b -> AltConst b x) -> (f x -> b) -> f x -> AltConst b x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f x -> b
forall x. f x -> b
f) (b -> AltConst b x
forall k w (a :: k). w -> AltConst w a
AltConst (b -> AltConst b x) -> (g x -> b) -> g x -> AltConst b x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g x -> b
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 x. f x -> b) -> (forall x. g x -> b) -> t f g a -> 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
!*! :: (f ~> h) -> (g ~> h) -> t f g ~> h
(!*!) = (f ~> h) -> (g ~> h) -> t f g x -> h x
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
!+! :: (f ~> h) -> (g ~> h) -> (f :+: g) ~> h
(!+!) f ~> h
f g ~> h
g = \case
    L1 f x
x -> f x -> h x
f ~> h
f f x
x
    R1 g x
y -> g x -> h x
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 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 = Op b a -> a -> b
forall a b. Op a b -> b -> a
getOp (Op b a -> a -> b) -> (t f g a -> Op b a) -> t f g a -> a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> Op b) -> (g ~> Op b) -> t f g ~> Op b
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *)
       (g :: * -> *) (h :: * -> *).
SemigroupIn t f =>
(g ~> f) -> (h ~> f) -> t g h ~> f
binterpret ((x -> b) -> Op b x
forall a b. (b -> a) -> Op a b
Op ((x -> b) -> Op b x) -> (f x -> x -> b) -> f x -> Op b x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f x -> x -> b
forall x. f x -> x -> b
f) ((x -> b) -> Op b x
forall a b. (b -> a) -> Op a b
Op ((x -> b) -> Op b x) -> (g x -> x -> b) -> g x -> Op b x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g x -> x -> b
forall x. g x -> x -> b
g)

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

    associating :: (f :*: (g :*: h)) <~> ((f :*: g) :*: h)
associating = ((f :*: (g :*: h)) ~> ((f :*: g) :*: h))
-> (((f :*: g) :*: h) ~> (f :*: (g :*: h)))
-> (f :*: (g :*: h)) <~> ((f :*: g) :*: h)
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (f :*: (g :*: h)) ~> ((f :*: g) :*: h)
forall k (f :: k -> *) (g :: k -> *) (g :: k -> *) (p :: k).
(:*:) f (g :*: g) p -> (:*:) (f :*: g) g p
to_ ((f :*: g) :*: h) ~> (f :*: (g :*: h))
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 f p -> g p -> (:*:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g p
y) (:*:) f g p -> g p -> (:*:) (f :*: g) g p
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 f p -> (:*:) f g p -> (:*:) f (f :*: g) p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (f p
y f p -> g p -> (:*:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g p
z)

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

    consNE :: (:*:) f (NonEmptyBy (:*:) f) x -> NonEmptyBy (:*:) f x
consNE (f x
x :*: NonEmptyF xs) = NonEmpty (f x) -> NonEmptyF f x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x) -> NonEmptyF f x)
-> NonEmpty (f x) -> NonEmptyF f x
forall a b. (a -> b) -> a -> b
$ f x
x f x -> [f x] -> NonEmpty (f x)
forall a. a -> [a] -> NonEmpty a
:| NonEmpty (f x) -> [f x]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (f x)
xs
    toNonEmptyBy :: (:*:) f f x -> NonEmptyBy (:*:) f x
toNonEmptyBy   (f x
x :*: f x
y           ) = NonEmpty (f x) -> NonEmptyF f x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x) -> NonEmptyF f x)
-> NonEmpty (f x) -> NonEmptyF f x
forall a b. (a -> b) -> a -> b
$ f x
x f x -> [f x] -> NonEmpty (f 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 x -> f x
biretract (f x
x :*: f x
y) = f x
x f x -> f x -> f x
forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
y
    binterpret :: (g ~> f) -> (h ~> f) -> (g :*: h) ~> f
binterpret g ~> f
f h ~> f
g (g x
x :*: h x
y) = g x -> f x
g ~> f
f g x
x f x -> f x -> f x
forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> h x -> f x
h ~> f
g h x
y

instance Associative Product where
    type NonEmptyBy Product = NonEmptyF

    associating :: Product f (Product g h) <~> Product (Product f g) h
associating = (Product f (Product g h) ~> Product (Product f g) h)
-> (Product (Product f g) h ~> Product f (Product g h))
-> Product f (Product g h) <~> Product (Product f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Product f (Product g h) ~> Product (Product f g) h
forall k (f :: k -> *) (g :: k -> *) (g :: k -> *) (a :: k).
Product f (Product g g) a -> Product (Product f g) g a
to_ Product (Product f g) h ~> Product f (Product g h)
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)) = Product f g a -> g a -> Product (Product f g) g a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (f a -> g a -> Product f g a
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) = f a -> Product f g a -> Product f (Product f g) a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
x (f a -> g a -> Product f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f a
y g a
z)

    appendNE :: Product (NonEmptyBy Product f) (NonEmptyBy Product f) x
-> NonEmptyBy Product f x
appendNE (NonEmptyF xs `Pair` NonEmptyF ys) = NonEmpty (f x) -> NonEmptyF f x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x)
xs NonEmpty (f x) -> NonEmpty (f x) -> NonEmpty (f x)
forall a. Semigroup a => a -> a -> a
<> NonEmpty (f x)
ys)
    matchNE :: 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 -> f x -> (:+:) f (Product f (NonEmptyF f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
y
        R1 NonEmptyF f x
zs     -> Product f (NonEmptyF f) x -> (:+:) f (Product f (NonEmptyF f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (Product f (NonEmptyF f) x -> (:+:) f (Product f (NonEmptyF f)) x)
-> Product f (NonEmptyF f) x -> (:+:) f (Product f (NonEmptyF f)) x
forall a b. (a -> b) -> a -> b
$ f x -> NonEmptyF f x -> Product f (NonEmptyF f) x
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 x. ListF f x -> (:+:) Proxy (NonEmptyF f) x
forall k (f :: k -> *). ListF f ~> (Proxy :+: NonEmptyF f)
fromListF (forall x. ListF f x -> (:+:) Proxy (NonEmptyF f) x)
-> (:*:) f (ListF f) x -> (:*:) f (Proxy :+: NonEmptyF f) x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
`hright` NonEmptyF f x -> (:*:) f (ListF f) x
forall k (f :: k -> *) (a :: k).
NonEmptyF f a -> (:*:) f (ListF f) a
nonEmptyProd NonEmptyF f x
NonEmptyBy Product f x
x

    consNE :: Product f (NonEmptyBy Product f) x -> NonEmptyBy Product f x
consNE (f x
x `Pair` NonEmptyF xs) = NonEmpty (f x) -> NonEmptyF f x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x) -> NonEmptyF f x)
-> NonEmpty (f x) -> NonEmptyF f x
forall a b. (a -> b) -> a -> b
$ f x
x f x -> [f x] -> NonEmpty (f x)
forall a. a -> [a] -> NonEmpty a
:| NonEmpty (f x) -> [f x]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (f x)
xs
    toNonEmptyBy :: Product f f x -> NonEmptyBy Product f x
toNonEmptyBy   (f x
x `Pair` f x
y           ) = NonEmpty (f x) -> NonEmptyF f x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (f x) -> NonEmptyF f x)
-> NonEmpty (f x) -> NonEmptyF f x
forall a b. (a -> b) -> a -> b
$ f x
x f x -> [f x] -> NonEmpty (f 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 x -> f x
biretract (Pair f x
x f x
y) = f x
x f x -> f x -> f x
forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
y
    binterpret :: (g ~> f) -> (h ~> f) -> Product g h ~> f
binterpret g ~> f
f h ~> f
g (Pair g x
x h x
y) = g x -> f x
g ~> f
f g x
x f x -> f x -> f x
forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> h x -> f x
h ~> f
g h x
y

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

    appendNE :: Day (NonEmptyBy Day f) (NonEmptyBy Day f) x -> NonEmptyBy Day f x
appendNE (Day NonEmptyBy Day f b
x NonEmptyBy Day f c
y b -> c -> x
z) = b -> c -> x
z (b -> c -> x) -> Ap1 f b -> Ap1 f (c -> x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ap1 f b
NonEmptyBy Day f b
x Ap1 f (c -> x) -> Ap1 f c -> Ap1 f x
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> Ap1 f c
NonEmptyBy Day f c
y
    matchNE :: NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE NonEmptyBy Day f x
a = case forall x. Ap f x -> (:+:) Identity (Ap1 f) x
forall (f :: * -> *). Ap f ~> (Identity :+: Ap1 f)
fromAp (forall x. Ap f x -> (:+:) Identity (Ap1 f) x)
-> Day f (Ap f) x -> Day f (Identity :+: Ap1 f) x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
`hright` Ap1 f x -> Day f (Ap f) x
forall (f :: * -> *) a. Ap1 f a -> Day f (Ap f) a
ap1Day Ap1 f x
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 y') -> f x -> (:+:) f (Day f (Ap1 f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (f x -> (:+:) f (Day f (Ap1 f)) x)
-> f x -> (:+:) f (Day f (Ap1 f)) x
forall a b. (a -> b) -> a -> b
$ (b -> c -> x
`z` c
y') (b -> x) -> f b -> f x
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
x
        R1 ys            -> Day f (Ap1 f) x -> (:+:) f (Day f (Ap1 f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (Day f (Ap1 f) x -> (:+:) f (Day f (Ap1 f)) x)
-> Day f (Ap1 f) x -> (:+:) f (Day f (Ap1 f)) x
forall a b. (a -> b) -> a -> b
$ f b -> Ap1 f c -> (b -> c -> x) -> Day f (Ap1 f) x
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 :: Day f (NonEmptyBy Day f) x -> NonEmptyBy Day f x
consNE (Day f b
x NonEmptyBy Day f c
y b -> c -> x
z) = f b -> Ap f (b -> x) -> Ap1 f x
forall (f :: * -> *) a b. f a -> Ap f (a -> b) -> Ap1 f b
Ap1 f b
x (Ap f (b -> x) -> Ap1 f x) -> Ap f (b -> x) -> Ap1 f x
forall a b. (a -> b) -> a -> b
$ (b -> c -> x) -> c -> b -> x
forall a b c. (a -> b -> c) -> b -> a -> c
flip b -> c -> x
z (c -> b -> x) -> Ap f c -> Ap f (b -> x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Ap1 f c -> Ap f c
forall (f :: * -> *). Ap1 f ~> Ap f
toAp Ap1 f c
NonEmptyBy Day f c
y
    toNonEmptyBy :: Day f f x -> NonEmptyBy Day f x
toNonEmptyBy   (Day f b
x f c
y b -> c -> x
z) = b -> c -> x
z (b -> c -> x) -> Ap1 f b -> Ap1 f (c -> x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b -> Ap1 f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f b
x Ap1 f (c -> x) -> Ap1 f c -> Ap1 f x
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> f c -> Ap1 f c
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 x -> f x
biretract (Day f b
x f c
y b -> c -> x
z) = b -> c -> x
z (b -> c -> x) -> f b -> f (c -> x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f b
x f (c -> x) -> f c -> f x
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> f c
y
    binterpret :: (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 (b -> c -> x) -> f b -> f (c -> x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> g b -> f b
g ~> f
f g b
x f (c -> x) -> f c -> f x
forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
<.> h c -> f c
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 :: Day f (Day g h) <~> Day (Day f g) h
associating = (Day f (Day g h) ~> Day (Day f g) h)
-> (Day (Day f g) h ~> Day f (Day g h))
-> Day f (Day g h) <~> Day (Day f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Day f (Day g h) ~> Day (Day f g) h
forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day f (Day g h) a -> Day (Day f g) h a
CD.assoc Day (Day f g) h ~> Day f (Day g h)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *) a.
Day (Day f g) h a -> Day f (Day g h) a
CD.disassoc

    appendNE :: Day (NonEmptyBy Day f) (NonEmptyBy Day f) x -> NonEmptyBy Day f x
appendNE (CD.Day NonEmptyBy Day f b
x NonEmptyBy Day f c
y x -> (b, c)
f) = (x -> (b, c)) -> Div1 f b -> Div1 f c -> Div1 f x
forall (f :: * -> *) a b c.
Divise f =>
(a -> (b, c)) -> f b -> f c -> f a
divise x -> (b, c)
f Div1 f b
NonEmptyBy Day f b
x Div1 f c
NonEmptyBy Day f c
y
    matchNE :: NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE = (Coyoneda f ~> f)
-> ((Coyoneda f :*: NonEmptyF (Coyoneda f)) ~> Day f (Div1 f))
-> (Coyoneda f :+: (Coyoneda f :*: NonEmptyF (Coyoneda f)))
   ~> (f :+: Day f (Div1 f))
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 Coyoneda f ~> f
forall (f :: * -> *) a. Contravariant f => Coyoneda f a -> f a
CCY.lowerCoyoneda (Coyoneda f :*: NonEmptyF (Coyoneda f)) ~> Day f (Div1 f)
forall (f :: * -> *) (f :: * -> *) p.
(:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) p -> Day f (Div1 f) p
go ((:+:) (Coyoneda f) (Coyoneda f :*: NonEmptyF (Coyoneda f)) x
 -> (:+:) f (Day f (Div1 f)) x)
-> (Div1 f x
    -> (:+:) (Coyoneda f) (Coyoneda f :*: NonEmptyF (Coyoneda f)) x)
-> Div1 f x
-> (:+:) f (Day f (Div1 f)) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *).
(Associative (:*:), FunctorBy (:*:) f) =>
NonEmptyBy (:*:) f ~> (f :+: (f :*: NonEmptyBy (:*:) f))
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE @(:*:) (NonEmptyF (Coyoneda f) x
 -> (:+:) (Coyoneda f) (Coyoneda f :*: NonEmptyF (Coyoneda f)) x)
-> (Div1 f x -> NonEmptyF (Coyoneda f) x)
-> Div1 f x
-> (:+:) (Coyoneda f) (Coyoneda f :*: NonEmptyF (Coyoneda f)) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Coyoneda f x) -> NonEmptyF (Coyoneda f) x
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF (NonEmpty (Coyoneda f x) -> NonEmptyF (Coyoneda f) x)
-> (Div1 f x -> NonEmpty (Coyoneda f x))
-> Div1 f x
-> NonEmptyF (Coyoneda f) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Div1 f x -> NonEmpty (Coyoneda f x)
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 xs) = f b -> Div1 f p -> (p -> (b, p)) -> Day f (Div1 f) p
forall (f :: * -> *) (g :: * -> *) a b c.
f b -> g c -> (a -> (b, c)) -> Day f g a
CD.Day f b
x (NonEmpty (Coyoneda f p) -> Div1 f p
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 :: Day f (NonEmptyBy Day f) x -> NonEmptyBy Day f x
consNE (CD.Day f b
x (Div1 xs) x -> (b, c)
f) = NonEmpty (Coyoneda f x) -> Div1 f x
forall (f :: * -> *) a. NonEmpty (Coyoneda f a) -> Div1 f a
Div1 (NonEmpty (Coyoneda f x) -> Div1 f x)
-> ((:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
    -> NonEmpty (Coyoneda f x))
-> (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
-> Div1 f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyF (Coyoneda f) x -> NonEmpty (Coyoneda f x)
forall k (f :: k -> *) (a :: k). NonEmptyF f a -> NonEmpty (f a)
runNonEmptyF (NonEmptyF (Coyoneda f) x -> NonEmpty (Coyoneda f x))
-> ((:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
    -> NonEmptyF (Coyoneda f) x)
-> (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
-> NonEmpty (Coyoneda f x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
-> NonEmptyF (Coyoneda f) x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE ((:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x -> Div1 f x)
-> (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x -> Div1 f x
forall a b. (a -> b) -> a -> b
$
        (x -> b) -> f b -> Coyoneda f x
forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda ((b, c) -> b
forall a b. (a, b) -> a
fst ((b, c) -> b) -> (x -> (b, c)) -> x -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) f b
x Coyoneda f x
-> NonEmptyF (Coyoneda f) x
-> (:*:) (Coyoneda f) (NonEmptyF (Coyoneda f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (x -> c) -> NonEmptyF (Coyoneda f) c -> NonEmptyF (Coyoneda f) x
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap ((b, c) -> c
forall a b. (a, b) -> b
snd ((b, c) -> c) -> (x -> (b, c)) -> x -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) (NonEmpty (Coyoneda f c) -> NonEmptyF (Coyoneda f) c
forall k (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF NonEmpty (Coyoneda f c)
xs)
    toNonEmptyBy :: Day f f x -> NonEmptyBy Day f x
toNonEmptyBy (CD.Day f b
x f c
y x -> (b, c)
f) = NonEmpty (Coyoneda f x) -> Div1 f x
forall (f :: * -> *) a. NonEmpty (Coyoneda f a) -> Div1 f a
Div1 (NonEmpty (Coyoneda f x) -> Div1 f x)
-> ((:*:) (Coyoneda f) (Coyoneda f) x -> NonEmpty (Coyoneda f x))
-> (:*:) (Coyoneda f) (Coyoneda f) x
-> Div1 f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyF (Coyoneda f) x -> NonEmpty (Coyoneda f x)
forall k (f :: k -> *) (a :: k). NonEmptyF f a -> NonEmpty (f a)
runNonEmptyF (NonEmptyF (Coyoneda f) x -> NonEmpty (Coyoneda f x))
-> ((:*:) (Coyoneda f) (Coyoneda f) x -> NonEmptyF (Coyoneda f) x)
-> (:*:) (Coyoneda f) (Coyoneda f) x
-> NonEmpty (Coyoneda f x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:*:) (Coyoneda f) (Coyoneda f) x -> NonEmptyF (Coyoneda f) x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy ((:*:) (Coyoneda f) (Coyoneda f) x -> Div1 f x)
-> (:*:) (Coyoneda f) (Coyoneda f) x -> Div1 f x
forall a b. (a -> b) -> a -> b
$
        (x -> b) -> f b -> Coyoneda f x
forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda ((b, c) -> b
forall a b. (a, b) -> a
fst ((b, c) -> b) -> (x -> (b, c)) -> x -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> (b, c)
f) f b
x Coyoneda f x -> Coyoneda f x -> (:*:) (Coyoneda f) (Coyoneda f) x
forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: (x -> c) -> f c -> Coyoneda f x
forall a b (f :: * -> *). (a -> b) -> f b -> Coyoneda f a
CCY.Coyoneda ((b, c) -> c
forall a b. (a, b) -> b
snd ((b, c) -> c) -> (x -> (b, c)) -> x -> c
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 x -> f x
biretract      (CD.Day f b
x f c
y x -> (b, c)
f) = (x -> (b, c)) -> f b -> f c -> f x
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 :: (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) = (x -> (b, c)) -> f b -> f c -> f x
forall (f :: * -> *) a b c.
Divise f =>
(a -> (b, c)) -> f b -> f c -> f a
divise x -> (b, c)
h (g b -> f b
g ~> f
f g b
x) (h c -> f c
h ~> f
g h c
y)

instance Associative ID.Day where
    type NonEmptyBy ID.Day = DivAp1
    type FunctorBy ID.Day = Invariant
    associating :: Day f (Day g h) <~> Day (Day f g) h
associating = (Day f (Day g h) ~> Day (Day f g) h)
-> (Day (Day f g) h ~> Day f (Day g h))
-> Day f (Day g h) <~> Day (Day f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Day f (Day g h) ~> Day (Day f g) h
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 Day (Day f g) h ~> Day f (Day g h)
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 :: Day (NonEmptyBy Day f) (NonEmptyBy Day f) x -> NonEmptyBy Day f x
appendNE = (Day (Chain1 Day f) (Chain1 Day f) x -> Chain1 Day f x)
-> Day (DivAp1 f) (DivAp1 f) x -> DivAp1 f x
coerce Day (Chain1 Day f) (Chain1 Day f) x -> Chain1 Day f x
forall (f :: * -> *).
Day (Chain1 Day f) (Chain1 Day f) ~> Chain1 Day f
appendNEIDay_
    matchNE :: NonEmptyBy Day f ~> (f :+: Day f (NonEmptyBy Day f))
matchNE = (Chain1 Day f x -> (:+:) f (Day f (Chain1 Day f)) x)
-> DivAp1 f x -> (:+:) f (Day f (DivAp1 f)) x
coerce Chain1 Day f x -> (:+:) f (Day f (Chain1 Day f)) x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1

    consNE :: Day f (NonEmptyBy Day f) x -> NonEmptyBy Day f x
consNE = (Day f (Chain1 Day f) x -> Chain1 Day f x)
-> Day f (DivAp1 f) x -> DivAp1 f x
coerce Day f (Chain1 Day f) x -> Chain1 Day f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1
    toNonEmptyBy :: Day f f x -> NonEmptyBy Day f x
toNonEmptyBy = (Day f f x -> Chain1 Day f x) -> Day f f x -> DivAp1 f x
coerce Day f f x -> Chain1 Day f x
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_ :: Day (Chain1 Day f) (Chain1 Day f) x -> Chain1 Day f x
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              -> Day f (Chain1 Day f) x -> Chain1 Day f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (f b
-> Chain1 Day f c
-> (b -> c -> x)
-> (x -> (b, c))
-> Day f (Chain1 Day f) x
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) -> Day f (Chain1 Day f) x -> Chain1 Day f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (Day f (Chain1 Day f) x -> Chain1 Day f x)
-> Day f (Chain1 Day f) x -> Chain1 Day f x
forall a b. (a -> b) -> a -> b
$
    f b
-> Chain1 Day f (c, c)
-> (b -> (c, c) -> x)
-> (x -> (b, (c, c)))
-> Day f (Chain1 Day f) x
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 (Day (Chain1 Day f) (Chain1 Day f) (c, c) -> Chain1 Day f (c, c)
forall (f :: * -> *).
Day (Chain1 Day f) (Chain1 Day f) ~> Chain1 Day f
appendNEIDay_ (Chain1 Day f c
-> Chain1 Day f c
-> (c -> c -> (c, c))
-> ((c, c) -> (c, c))
-> Day (Chain1 Day f) (Chain1 Day f) (c, c)
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 (,) (c, c) -> (c, c)
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)
      (((b, c), c) -> (b, (c, c))
forall (p :: * -> * -> *) a b c.
Assoc p =>
p (p a b) c -> p a (p b c)
B.assoc (((b, c), c) -> (b, (c, c)))
-> (x -> ((b, c), c)) -> x -> (b, (c, c))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> (b, c)) -> (b, c) -> ((b, c), c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> (b, c)
h ((b, c) -> ((b, c), c)) -> (x -> (b, c)) -> x -> ((b, c), c)
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 x -> f x
biretract = Day f f x -> f x
forall (f :: * -> *). Inply f => Day f f ~> f
dather
    binterpret :: (g ~> f) -> (h ~> f) -> Day g h ~> f
binterpret = (g ~> f) -> (h ~> f) -> Day g h x -> f x
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 :: Night f (Night g h) <~> Night (Night f g) h
associating = (Night f (Night g h) ~> Night (Night f g) h)
-> (Night (Night f g) h ~> Night f (Night g h))
-> Night f (Night g h) <~> Night (Night f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Night f (Night g h) ~> Night (Night f g) h
forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night f (Night g h) ~> Night (Night f g) h
IN.assoc Night (Night f g) h ~> Night f (Night g h)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night (Night f g) h ~> Night f (Night g h)
IN.unassoc

    appendNE :: Night (NonEmptyBy Night f) (NonEmptyBy Night f) x
-> NonEmptyBy Night f x
appendNE = (Night (Chain1 Night f) (Chain1 Night f) x -> Chain1 Night f x)
-> Night (DecAlt1 f) (DecAlt1 f) x -> DecAlt1 f x
coerce Night (Chain1 Night f) (Chain1 Night f) x -> Chain1 Night f x
forall (f :: * -> *).
Night (Chain1 Night f) (Chain1 Night f) ~> Chain1 Night f
appendNEINight_
    matchNE :: NonEmptyBy Night f ~> (f :+: Night f (NonEmptyBy Night f))
matchNE = (Chain1 Night f x -> (:+:) f (Night f (Chain1 Night f)) x)
-> DecAlt1 f x -> (:+:) f (Night f (DecAlt1 f)) x
coerce Chain1 Night f x -> (:+:) f (Night f (Chain1 Night f)) x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *).
Chain1 t f ~> (f :+: t f (Chain1 t f))
matchChain1

    consNE :: Night f (NonEmptyBy Night f) x -> NonEmptyBy Night f x
consNE = (Night f (Chain1 Night f) x -> Chain1 Night f x)
-> Night f (DecAlt1 f) x -> DecAlt1 f x
coerce Night f (Chain1 Night f) x -> Chain1 Night f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1
    toNonEmptyBy :: Night f f x -> NonEmptyBy Night f x
toNonEmptyBy = (Night f f x -> Chain1 Night f x) -> Night f f x -> DecAlt1 f x
coerce Night f f x -> Chain1 Night f x
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_ :: Night (Chain1 Night f) (Chain1 Night f) x -> Chain1 Night f x
appendNEINight_ (IN.Night Chain1 Night f b
xs Chain1 Night f c
ys b -> x
f c -> x
g x -> Either b c
h) = case Chain1 Night f b
xs of
  Done1 f b
x                     -> Night f (Chain1 Night f) x -> Chain1 Night f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (f b
-> Chain1 Night f c
-> (b -> x)
-> (c -> x)
-> (x -> Either b c)
-> Night f (Chain1 Night f) x
forall (f :: * -> *) b (g :: * -> *) c a.
f b
-> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a
IN.Night f b
x Chain1 Night f c
ys b -> x
f c -> x
g x -> Either b c
h)
  More1 (IN.Night f b
z Chain1 Night f c
zs b -> b
j c -> b
k b -> Either b c
l) -> Night f (Chain1 Night f) x -> Chain1 Night f x
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (a :: k).
t f (Chain1 t f) a -> Chain1 t f a
More1 (Night f (Chain1 Night f) x -> Chain1 Night f x)
-> Night f (Chain1 Night f) x -> Chain1 Night f x
forall a b. (a -> b) -> a -> b
$
    f b
-> Chain1 Night f (Either c c)
-> (b -> x)
-> (Either c c -> x)
-> (x -> Either b (Either c c))
-> Night f (Chain1 Night f) x
forall (f :: * -> *) b (g :: * -> *) c a.
f b
-> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a
IN.Night f b
z (Night (Chain1 Night f) (Chain1 Night f) (Either c c)
-> Chain1 Night f (Either c c)
forall (f :: * -> *).
Night (Chain1 Night f) (Chain1 Night f) ~> Chain1 Night f
appendNEINight_ (Chain1 Night f c
-> Chain1 Night f c
-> (c -> Either c c)
-> (c -> Either c c)
-> (Either c c -> Either c c)
-> Night (Chain1 Night f) (Chain1 Night f) (Either c c)
forall (f :: * -> *) b (g :: * -> *) c a.
f b
-> g c -> (b -> a) -> (c -> a) -> (a -> Either b c) -> Night f g a
IN.Night Chain1 Night f c
zs Chain1 Night f c
ys c -> Either c c
forall a b. a -> Either a b
Left c -> Either c c
forall a b. b -> Either a b
Right Either c c -> Either c c
forall a. a -> a
id))
      (b -> x
f (b -> x) -> (b -> b) -> b -> x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> b
j)
      ((c -> x) -> (c -> x) -> Either c c -> x
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (b -> x
f (b -> x) -> (c -> b) -> c -> x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> b
k) c -> x
g)
      (Either (Either b c) c -> Either b (Either c c)
forall (p :: * -> * -> *) a b c.
Assoc p =>
p (p a b) c -> p a (p b c)
B.assoc (Either (Either b c) c -> Either b (Either c c))
-> (x -> Either (Either b c) c) -> x -> Either b (Either c c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> Either b c) -> Either b c -> Either (Either b c) c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first b -> Either b c
l (Either b c -> Either (Either b c) c)
-> (x -> Either b c) -> x -> Either (Either b c) c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> Either b c
h)

-- | @since 0.4.0.0
instance Inalt f => SemigroupIn IN.Night f where
    biretract :: Night f f x -> f x
biretract = Night f f x -> f x
forall (f :: * -> *). Inalt f => Night f f ~> f
IN.nerve
    binterpret :: (g ~> f) -> (h ~> f) -> Night g h ~> f
binterpret = (g ~> f) -> (h ~> f) -> Night g h x -> f x
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 :: Night f (Night g h) <~> Night (Night f g) h
associating = (Night f (Night g h) ~> Night (Night f g) h)
-> (Night (Night f g) h ~> Night f (Night g h))
-> Night f (Night g h) <~> Night (Night f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Night f (Night g h) ~> Night (Night f g) h
forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night f (Night g h) ~> Night (Night f g) h
N.assoc Night (Night f g) h ~> Night f (Night g h)
forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
Night (Night f g) h ~> Night f (Night g h)
N.unassoc

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

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

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

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

    associating :: (f :+: (g :+: h)) <~> ((f :+: g) :+: h)
associating = ((f :+: (g :+: h)) ~> ((f :+: g) :+: h))
-> (((f :+: g) :+: h) ~> (f :+: (g :+: h)))
-> (f :+: (g :+: h)) <~> ((f :+: g) :+: h)
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (f :+: (g :+: h)) ~> ((f :+: g) :+: h)
forall k (f :: k -> *) (g :: k -> *) (g :: k -> *) (p :: k).
(:+:) f (g :+: g) p -> (:+:) (f :+: g) g p
to_ ((f :+: g) :+: h) ~> (f :+: (g :+: h))
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      -> (:+:) f g p -> (:+:) (f :+: g) g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (f p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
x)
          R1 (L1 g p
y) -> (:+:) f g p -> (:+:) (f :+: g) g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 (g p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 g p
y)
          R1 (R1 g p
z) -> g p -> (:+:) (f :+: g) g p
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) -> f p -> (:+:) f (f :+: g) p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
x
          L1 (R1 f p
y) -> (:+:) f g p -> (:+:) f (f :+: g) p
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (f p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f p
y)
          R1 g p
z      -> (:+:) f g p -> (:+:) f (f :+: g) p
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (g p -> (:+:) f g p
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 g p
z)

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

    consNE :: (:+:) f (NonEmptyBy (:+:) f) x -> NonEmptyBy (:+:) f x
consNE = (:+:) f (Step f) x -> Step f x
forall k (f :: k -> *). (f :+: Step f) ~> Step f
stepUp ((:+:) f (Step f) x -> Step f x)
-> ((:+:) f (Step f) x -> (:+:) f (Step f) x)
-> (:+:) f (Step f) x
-> Step f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Step f x -> (:+:) f (Step f) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (Step f x -> (:+:) f (Step f) x)
-> ((:+:) f (Step f) x -> Step f x)
-> (:+:) f (Step f) x
-> (:+:) f (Step f) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:) f (Step f) x -> Step f x
forall k (f :: k -> *). (f :+: Step f) ~> Step f
stepUp
    toNonEmptyBy :: (:+:) f f x -> NonEmptyBy (:+:) f x
toNonEmptyBy = \case
      L1 f x
x -> Natural -> f x -> Step f x
forall k (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
1 f x
x
      R1 f x
y -> Natural -> f x -> Step f x
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 x -> f x
biretract = \case
      L1 f x
x -> f x
x
      R1 f x
y -> f x
y
    binterpret :: (g ~> f) -> (h ~> f) -> (g :+: h) ~> f
binterpret g ~> f
f h ~> f
g = \case
      L1 g x
x -> g x -> f x
g ~> f
f g x
x
      R1 h x
y -> h x -> f x
h ~> f
g h x
y

instance Associative Sum where
    type NonEmptyBy Sum = Step
    associating :: Sum f (Sum g h) <~> Sum (Sum f g) h
associating = (Sum f (Sum g h) ~> Sum (Sum f g) h)
-> (Sum (Sum f g) h ~> Sum f (Sum g h))
-> Sum f (Sum g h) <~> Sum (Sum f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Sum f (Sum g h) ~> Sum (Sum f g) h
forall k (f :: k -> *) (g :: k -> *) (g :: k -> *) (a :: k).
Sum f (Sum g g) a -> Sum (Sum f g) g a
to_ Sum (Sum f g) h ~> Sum f (Sum g h)
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       -> Sum f g a -> Sum (Sum f g) g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (f a -> Sum f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
x)
          InR (InL g a
y) -> Sum f g a -> Sum (Sum f g) g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (g a -> Sum f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g a
y)
          InR (InR g a
z) -> g a -> Sum (Sum f g) g a
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) -> f a -> Sum f (Sum f g) a
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
x
          InL (InR f a
y) -> Sum f g a -> Sum f (Sum f g) a
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (f a -> Sum f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f a
y)
          InR g a
z       -> Sum f g a -> Sum f (Sum f g) a
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (g a -> Sum f g a
forall k (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g a
z)

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

    consNE :: Sum f (NonEmptyBy Sum f) x -> NonEmptyBy Sum f x
consNE = (:+:) f (Step f) x -> Step f x
forall k (f :: k -> *). (f :+: Step f) ~> Step f
stepUp ((:+:) f (Step f) x -> Step f x)
-> (Sum f (Step f) x -> (:+:) f (Step f) x)
-> Sum f (Step f) x
-> Step f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Step f x -> (:+:) f (Step f) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (Step f x -> (:+:) f (Step f) x)
-> (Sum f (Step f) x -> Step f x)
-> Sum f (Step f) x
-> (:+:) f (Step f) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (:+:) f (Step f) x -> Step f x
forall k (f :: k -> *). (f :+: Step f) ~> Step f
stepUp ((:+:) f (Step f) x -> Step f x)
-> (Sum f (Step f) x -> (:+:) f (Step f) x)
-> Sum f (Step f) x
-> Step f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((f :+: Step f) <~> Sum f (Step f))
-> Sum f (Step f) ~> (f :+: Step f)
forall k (f :: k -> *) (g :: k -> *). (f <~> g) -> g ~> f
reviewF forall k (f :: k -> *) (g :: k -> *). (f :+: g) <~> Sum f g
(f :+: Step f) <~> Sum f (Step f)
sumSum
    toNonEmptyBy :: Sum f f x -> NonEmptyBy Sum f x
toNonEmptyBy = \case
      InL f x
x -> Natural -> f x -> Step f x
forall k (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
1 f x
x
      InR f x
y -> Natural -> f x -> Step f x
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 x -> f x
biretract = \case
      InR f x
x -> f x
x
      InL f x
y -> f x
y
    binterpret :: (g ~> f) -> (h ~> f) -> Sum g h ~> f
binterpret g ~> f
f h ~> f
g = \case
      InL g x
x -> g x -> f x
g ~> f
f g x
x
      InR h x
y -> h x -> f x
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 :: These1 f (These1 g h) <~> These1 (These1 f g) h
associating = (These1 f (These1 g h) ~> These1 (These1 f g) h)
-> (These1 (These1 f g) h ~> These1 f (These1 g h))
-> These1 f (These1 g h) <~> These1 (These1 f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF These1 f (These1 g h) ~> These1 (These1 f g) h
forall (f :: * -> *) (g :: * -> *) (g :: * -> *) a.
These1 f (These1 g g) a -> These1 (These1 f g) g a
to_ These1 (These1 f g) h ~> These1 f (These1 g h)
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              -> These1 f g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (f a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
x  )
          That1    (This1  g a
y  ) -> These1 f g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
y)
          That1    (That1    g a
z) -> g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1               g a
z
          That1    (These1 g a
y g a
z) -> These1 f g a -> g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (g a -> These1 f g a
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  ) -> These1 f g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  (f a -> g a -> These1 f g a
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) -> These1 f g a -> g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (f a -> These1 f g a
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) -> These1 f g a -> g a -> These1 (These1 f g) g a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (f a -> g a -> These1 f g a
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  )   -> f a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
x
          This1  (That1    f a
y)   -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (f a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
y  )
          This1  (These1 f a
x f a
y)   -> f a -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (f a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1  f a
y  )
          That1               g a
z -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
z)
          These1 (This1  f a
x  ) g a
z -> f a -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    g a
z)
          These1 (That1    f a
y) g a
z -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. g a -> These1 f g a
That1    (f a -> g a -> These1 f g a
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 -> f a -> These1 f g a -> These1 f (These1 f g) a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
x (f a -> g a -> These1 f g a
forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 f a
y g a
z)

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

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

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

instance Associative Void3 where
    type NonEmptyBy Void3 = IdentityT
    associating :: Void3 f (Void3 g h) <~> Void3 (Void3 f g) h
associating = (Void3 f (Void3 g h) ~> Void3 (Void3 f g) h)
-> (Void3 (Void3 f g) h ~> Void3 f (Void3 g h))
-> Void3 f (Void3 g h) <~> Void3 (Void3 f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Void3 f (Void3 g h) ~> Void3 (Void3 f g) h
coerce Void3 (Void3 f g) h ~> Void3 f (Void3 g h)
coerce

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

    consNE :: Void3 f (NonEmptyBy Void3 f) x -> NonEmptyBy Void3 f x
consNE = \case {}
    toNonEmptyBy :: Void3 f f x -> NonEmptyBy Void3 f x
toNonEmptyBy   = \case {}

-- | All functors are semigroups in the semigroupoidal category on 'Void3'.
instance SemigroupIn Void3 f where
    biretract :: Void3 f f x -> f x
biretract = \case {}
    binterpret :: (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 :: Comp f (Comp g h) <~> Comp (Comp f g) h
associating = (Comp f (Comp g h) ~> Comp (Comp f g) h)
-> (Comp (Comp f g) h ~> Comp f (Comp g h))
-> Comp f (Comp g h) <~> Comp (Comp f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF Comp f (Comp g h) ~> Comp (Comp f g) h
forall k (g :: * -> *) (f :: * -> *) (g :: k -> *) (a :: k).
Functor g =>
Comp f (Comp g g) a -> Comp (Comp f g) g a
to_ Comp (Comp f g) h ~> Comp f (Comp g h)
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 f x -> (x -> g (g a)) -> Comp f g (g a)
forall k (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= (Comp g g a -> g (g a)
forall (f :: * -> *) k (g :: k -> *) (a :: k).
Comp f g a -> Functor f => f (g a)
unComp (Comp g g a -> g (g a)) -> (x -> Comp g g a) -> x -> g (g a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> Comp g g a
y)) Comp f g (g a) -> (g a -> g a) -> Comp (Comp f g) g a
forall k (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= g a -> g a
forall a. a -> a
id
        from_ :: Comp (Comp f g) g a -> Comp f (Comp g g) a
from_ ((x :>>= y) :>>= x -> g a
z) = f x
x f x -> (x -> Comp g g a) -> Comp f (Comp g g) a
forall k (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= ((g x -> (x -> g a) -> Comp g g a
forall k (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= x -> g a
z) (g x -> Comp g g a) -> (x -> g x) -> x -> Comp g g a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. x -> g x
y)

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

    consNE :: Comp f (NonEmptyBy Comp f) x -> NonEmptyBy Comp f x
consNE (f x
x :>>= x -> NonEmptyBy Comp f x
y) = f x -> Free1 f x
forall (f :: * -> *). f ~> Free1 f
liftFree1 f x
x Free1 f x -> (x -> Free1 f x) -> Free1 f x
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- x -> Free1 f x
x -> NonEmptyBy Comp f x
y
    toNonEmptyBy :: Comp f f x -> NonEmptyBy Comp f x
toNonEmptyBy   (f x
x :>>= x -> f x
g) = f x -> Free1 f x
forall (f :: * -> *). f ~> Free1 f
liftFree1 f x
x Free1 f x -> (x -> Free1 f x) -> Free1 f x
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- f x -> Free1 f x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject (f x -> Free1 f x) -> (x -> f x) -> x -> Free1 f x
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 x -> f x
biretract      (f x
x :>>= x -> f x
y) = f x
x f x -> (x -> f x) -> f x
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- x -> f x
y
    binterpret :: (g ~> f) -> (h ~> f) -> Comp g h ~> f
binterpret g ~> f
f h ~> f
g (g x
x :>>= x -> h x
y) = g x -> f x
g ~> f
f g x
x f x -> (x -> f x) -> f x
forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
>>- (h x -> f x
h ~> f
g (h x -> f x) -> (x -> h x) -> x -> f x
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 :: Joker f (Joker g h) <~> Joker (Joker f g) h
associating = (Joker f (Joker g h) ~> Joker (Joker f g) h)
-> (Joker (Joker f g) h ~> Joker f (Joker g h))
-> Joker f (Joker g h) <~> Joker (Joker f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (Joker f g x -> Joker (Joker f g) h x
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker (Joker f g x -> Joker (Joker f g) h x)
-> (Joker f (Joker g h) x -> Joker f g x)
-> Joker f (Joker g h) x
-> Joker (Joker f g) h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f x -> Joker f g x
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker    (f x -> Joker f g x)
-> (Joker f (Joker g h) x -> f x)
-> Joker f (Joker g h) x
-> Joker f g x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker f (Joker g h) x -> f x
forall k1 (g :: k1 -> *) k2 (a :: k2) (b :: k1). Joker g a b -> g b
runJoker)
                       (f x -> Joker f (Joker g h) x
forall k k1 (g :: k -> *) (a :: k1) (b :: k). g b -> Joker g a b
Joker (f x -> Joker f (Joker g h) x)
-> (Joker (Joker f g) h x -> f x)
-> Joker (Joker f g) h x
-> Joker f (Joker g h) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker f g x -> f x
forall k1 (g :: k1 -> *) k2 (a :: k2) (b :: k1). Joker g a b -> g b
runJoker (Joker f g x -> f x)
-> (Joker (Joker f g) h x -> Joker f g x)
-> Joker (Joker f g) h x
-> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker (Joker f g) h x -> Joker f g x
forall k1 (g :: k1 -> *) k2 (a :: k2) (b :: k1). Joker g a b -> g b
runJoker)
    appendNE :: Joker (NonEmptyBy Joker f) (NonEmptyBy Joker f) x
-> NonEmptyBy Joker f x
appendNE (Joker (Flagged _ x)) = Bool -> f x -> Flagged f x
forall k (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True f x
x
    matchNE :: NonEmptyBy Joker f ~> (f :+: Joker f (NonEmptyBy Joker f))
matchNE (Flagged False x) = f x -> (:+:) f (Joker f (Flagged f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
    matchNE (Flagged True  x) = Joker f (Flagged f) x -> (:+:) f (Joker f (Flagged f)) x
forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 (Joker f (Flagged f) x -> (:+:) f (Joker f (Flagged f)) x)
-> Joker f (Flagged f) x -> (:+:) f (Joker f (Flagged f)) x
forall a b. (a -> b) -> a -> b
$ f x -> Joker f (Flagged f) x
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 x -> f x
biretract = Joker f f x -> f x
forall k1 (g :: k1 -> *) k2 (a :: k2) (b :: k1). Joker g a b -> g b
runJoker
    binterpret :: (g ~> f) -> (h ~> f) -> Joker g h ~> f
binterpret g ~> f
f h ~> f
_ = g x -> f x
g ~> f
f (g x -> f x) -> (Joker g h x -> g x) -> Joker g h x -> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Joker g h x -> g x
forall k1 (g :: k1 -> *) k2 (a :: k2) (b :: k1). Joker g a b -> g b
runJoker

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

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

    consNE :: LeftF f (NonEmptyBy LeftF f) x -> NonEmptyBy LeftF f x
consNE = Bool -> f x -> Flagged f x
forall k (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True (f x -> Flagged f x)
-> (LeftF f (Flagged f) x -> f x)
-> LeftF f (Flagged f) x
-> Flagged f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeftF f (Flagged f) x -> f x
forall k (f :: k -> *) k (g :: k) (a :: k). LeftF f g a -> f a
runLeftF
    toNonEmptyBy :: LeftF f f x -> NonEmptyBy LeftF f x
toNonEmptyBy   = Bool -> f x -> Flagged f x
forall k (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
True (f x -> Flagged f x)
-> (LeftF f f x -> f x) -> LeftF f f x -> Flagged f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LeftF f f x -> f x
forall k (f :: k -> *) k (g :: k) (a :: k). LeftF f g a -> f a
runLeftF

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

instance Associative RightF where
    type NonEmptyBy RightF = Step

    associating :: RightF f (RightF g h) <~> RightF (RightF f g) h
associating = (RightF f (RightF g h) ~> RightF (RightF f g) h)
-> (RightF (RightF f g) h ~> RightF f (RightF g h))
-> RightF f (RightF g h) <~> RightF (RightF f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (h x -> RightF (RightF f g) h x
forall k k (f :: k) (g :: k -> *) (a :: k). g a -> RightF f g a
RightF (h x -> RightF (RightF f g) h x)
-> (RightF f (RightF g h) x -> h x)
-> RightF f (RightF g h) x
-> RightF (RightF f g) h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RightF g h x -> h x
forall k (f :: k) k (g :: k -> *) (a :: k). RightF f g a -> g a
runRightF (RightF g h x -> h x)
-> (RightF f (RightF g h) x -> RightF g h x)
-> RightF f (RightF g h) x
-> h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RightF f (RightF g h) x -> RightF g h x
forall k (f :: k) k (g :: k -> *) (a :: k). RightF f g a -> g a
runRightF)
                       (RightF g h x -> RightF f (RightF g h) x
forall k k (f :: k) (g :: k -> *) (a :: k). g a -> RightF f g a
RightF (RightF g h x -> RightF f (RightF g h) x)
-> (RightF (RightF f g) h x -> RightF g h x)
-> RightF (RightF f g) h x
-> RightF f (RightF g h) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. h x -> RightF g h x
forall k k (f :: k) (g :: k -> *) (a :: k). g a -> RightF f g a
RightF    (h x -> RightF g h x)
-> (RightF (RightF f g) h x -> h x)
-> RightF (RightF f g) h x
-> RightF g h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RightF (RightF f g) h x -> h x
forall k (f :: k) k (g :: k -> *) (a :: k). RightF f g a -> g a
runRightF)

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

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

instance SemigroupIn RightF f where
    biretract :: RightF f f x -> f x
biretract      = RightF f f x -> f x
forall k (f :: k) k (g :: k -> *) (a :: k). RightF f g a -> g a
runRightF
    binterpret :: (g ~> f) -> (h ~> f) -> RightF g h ~> f
binterpret g ~> f
_ h ~> f
g = h x -> f x
h ~> f
g (h x -> f x) -> (RightF g h x -> h x) -> RightF g h x -> f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RightF g h x -> h x
forall k (f :: k) k (g :: k -> *) (a :: k). 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 { WrapHBF t f g a -> t f g a
unwrapHBF :: t f g a }
  deriving (Int -> WrapHBF t f g a -> ShowS
[WrapHBF t f g a] -> ShowS
WrapHBF t f g a -> String
(Int -> WrapHBF t f g a -> ShowS)
-> (WrapHBF t f g a -> String)
-> ([WrapHBF t f g a] -> ShowS)
-> Show (WrapHBF t f g a)
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)
Int -> ReadS (WrapHBF t f g a)
ReadS [WrapHBF t f g a]
(Int -> ReadS (WrapHBF t f g a))
-> ReadS [WrapHBF t f g a]
-> ReadPrec (WrapHBF t f g a)
-> ReadPrec [WrapHBF t f g a]
-> Read (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
(WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> Eq (WrapHBF t f g a)
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, Eq (WrapHBF t f g a)
Eq (WrapHBF t f g a)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Ordering)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> (WrapHBF t f g a -> WrapHBF t f g a -> Bool)
-> (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 -> WrapHBF t f g a)
-> Ord (WrapHBF 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 -> 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
$cp1Ord :: 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)
Ord, a -> WrapHBF t f g b -> WrapHBF t f g a
(a -> b) -> WrapHBF t f g a -> WrapHBF t f g b
(forall a b. (a -> b) -> WrapHBF t f g a -> WrapHBF t f g b)
-> (forall a b. a -> WrapHBF t f g b -> WrapHBF t f g a)
-> Functor (WrapHBF t f g)
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
<$ :: 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 :: (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, a -> WrapHBF t f g a -> Bool
WrapHBF t f g m -> m
WrapHBF t f g a -> [a]
WrapHBF t f g a -> Bool
WrapHBF t f g a -> Int
WrapHBF t f g a -> a
WrapHBF t f g a -> a
WrapHBF t f g a -> a
WrapHBF t f g a -> a
(a -> m) -> WrapHBF t f g a -> m
(a -> m) -> WrapHBF t f g a -> m
(a -> b -> b) -> b -> WrapHBF t f g a -> b
(a -> b -> b) -> b -> WrapHBF t f g a -> b
(b -> a -> b) -> b -> WrapHBF t f g a -> b
(b -> a -> b) -> b -> WrapHBF t f g a -> b
(a -> a -> a) -> WrapHBF t f g a -> a
(a -> a -> a) -> WrapHBF t f g a -> a
(forall m. Monoid m => WrapHBF t f g m -> m)
-> (forall m a. Monoid m => (a -> m) -> WrapHBF t f g a -> m)
-> (forall m a. Monoid m => (a -> m) -> WrapHBF t f g a -> m)
-> (forall a b. (a -> b -> b) -> b -> WrapHBF t f g a -> b)
-> (forall a b. (a -> b -> b) -> b -> WrapHBF t f g a -> b)
-> (forall b a. (b -> a -> b) -> b -> WrapHBF t f g a -> b)
-> (forall b a. (b -> a -> b) -> b -> WrapHBF t f g a -> b)
-> (forall a. (a -> a -> a) -> WrapHBF t f g a -> a)
-> (forall a. (a -> a -> a) -> WrapHBF t f g a -> a)
-> (forall a. WrapHBF t f g a -> [a])
-> (forall a. WrapHBF t f g a -> Bool)
-> (forall a. WrapHBF t f g a -> Int)
-> (forall a. Eq a => a -> WrapHBF t f g a -> Bool)
-> (forall a. Ord a => WrapHBF t f g a -> a)
-> (forall a. Ord a => WrapHBF t f g a -> a)
-> (forall a. Num a => WrapHBF t f g a -> a)
-> (forall a. Num a => WrapHBF t f g a -> a)
-> Foldable (WrapHBF t f g)
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 :: 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 :: 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 :: 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 :: 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 :: 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 :: 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 :: 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 :: 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 :: (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 :: (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' :: (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 :: (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' :: (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 :: (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' :: (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 :: (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 :: 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, Functor (WrapHBF t f g)
Foldable (WrapHBF t f g)
Functor (WrapHBF t f g)
-> Foldable (WrapHBF t f g)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    WrapHBF t f g (f a) -> f (WrapHBF t f g a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> WrapHBF t f g a -> m (WrapHBF t f g b))
-> (forall (m :: * -> *) a.
    Monad m =>
    WrapHBF t f g (m a) -> m (WrapHBF t f g a))
-> Traversable (WrapHBF t f g)
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
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 (m :: * -> *) a.
Monad m =>
WrapHBF t f g (m a) -> m (WrapHBF t f g a)
forall (f :: * -> *) a.
Applicative f =>
WrapHBF t f g (f a) -> f (WrapHBF t f g a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> WrapHBF t f g a -> m (WrapHBF t f g b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> WrapHBF t f g a -> f (WrapHBF t f g b)
sequence :: 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 :: (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 :: 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 :: (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)
$cp2Traversable :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k).
Traversable (t f g) =>
Foldable (WrapHBF t f g)
$cp1Traversable :: forall k k (t :: k -> k -> * -> *) (f :: k) (g :: k).
Traversable (t f g) =>
Functor (WrapHBF t f g)
Traversable, Typeable, (forall x. WrapHBF t f g a -> Rep (WrapHBF t f g a) x)
-> (forall x. Rep (WrapHBF t f g a) x -> WrapHBF t f g a)
-> Generic (WrapHBF t f g a)
forall x. Rep (WrapHBF t f g a) x -> WrapHBF t f g a
forall x. WrapHBF t f g a -> Rep (WrapHBF t f g a) x
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, Typeable (WrapHBF t f g a)
DataType
Constr
Typeable (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))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a))
-> (WrapHBF t f g a -> Constr)
-> (WrapHBF t f g a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (WrapHBF t f g a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (WrapHBF t f g a)))
-> ((forall b. Data b => b -> b)
    -> WrapHBF t f g a -> WrapHBF t f g a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> WrapHBF t f g a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> WrapHBF t f g a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> WrapHBF t f g a -> m (WrapHBF t f g a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> WrapHBF t f g a -> m (WrapHBF t f g a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> WrapHBF t f g a -> m (WrapHBF t f g a))
-> Data (WrapHBF t f g a)
WrapHBF t f g a -> DataType
WrapHBF t f g a -> Constr
(forall b. Data b => b -> b) -> WrapHBF t f g a -> WrapHBF 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 b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (WrapHBF t f g a)
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 u.
Int -> (forall d. Data d => d -> u) -> WrapHBF t f g a -> u
forall u. (forall d. Data d => d -> u) -> WrapHBF t f g a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> WrapHBF t f g a -> r
forall r r'.
(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).
(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 (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (WrapHBF t f g a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> WrapHBF t f g a -> m (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)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (WrapHBF t f g a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (WrapHBF t f g a))
$cWrapHBF :: Constr
$tWrapHBF :: DataType
gmapMo :: (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 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 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 :: 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 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 :: (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 :: (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 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 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 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 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)
$cp1Data :: 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)
Data)

instance Show1 (t f g) => Show1 (WrapHBF t f g) where
    liftShowsPrec :: (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) = (Int -> t f g a -> ShowS) -> String -> Int -> t f g a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> t f g a -> ShowS
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 :: (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) = (a -> b -> Bool) -> t f g a -> t f g b -> Bool
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 :: (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) = (a -> b -> Ordering) -> t f g a -> t f g b -> Ordering
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 :: (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) = t j l x -> WrapHBF t j l 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 ((f ~> j) -> (g ~> l) -> t f g x -> t j l x
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 :: (f ~> j) -> WrapHBF t f g ~> WrapHBF t j g
hleft f ~> j
f (WrapHBF t f g x
x) = t j g x -> WrapHBF t j g 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 ((f ~> j) -> t f g x -> t j g x
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 :: (g ~> l) -> WrapHBF t f g ~> WrapHBF t f l
hright g ~> l
g (WrapHBF t f g x
x) = t f l x -> WrapHBF t f l 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 ((g ~> l) -> t f g x -> t f l x
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 :: WrapHBF t f (WrapHBF t g h) <~> WrapHBF t (WrapHBF t f g) h
associating = (WrapHBF t f (WrapHBF t g h) ~> t f (t g h))
-> (t f (t g h) ~> WrapHBF t f (WrapHBF t g h))
-> WrapHBF t f (WrapHBF t g h) <~> t f (t g h)
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF ((WrapHBF t g h ~> t g h) -> t f (WrapHBF t g h) ~> t f (t g h)
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright WrapHBF t g h ~> t g h
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 (WrapHBF t g h) x -> t f (t g h) x)
-> (WrapHBF t f (WrapHBF t g h) x -> t f (WrapHBF t g h) x)
-> WrapHBF t f (WrapHBF t g h) x
-> t f (t g h) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t f (WrapHBF t g h) x -> t f (WrapHBF t g h) x
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 (WrapHBF t g h) x -> WrapHBF t f (WrapHBF t g h) 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 (t f (WrapHBF t g h) x -> WrapHBF t f (WrapHBF t g h) x)
-> (t f (t g h) x -> t f (WrapHBF t g h) x)
-> t f (t g h) x
-> WrapHBF t f (WrapHBF t g h) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t g h ~> WrapHBF t g h) -> t f (t g h) ~> t f (WrapHBF t g h)
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright t g h ~> WrapHBF t g h
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF)
                (p (t f (t g h) a) (t f (t g h) a)
 -> p (WrapHBF t f (WrapHBF t g h) a)
      (WrapHBF t f (WrapHBF t g h) a))
-> (p (WrapHBF t (WrapHBF t f g) h a)
      (WrapHBF t (WrapHBF t f g) h a)
    -> p (t f (t g h) a) (t f (t g h) a))
-> p (WrapHBF t (WrapHBF t f g) h a)
     (WrapHBF t (WrapHBF t f g) h a)
-> p (WrapHBF t f (WrapHBF t g h) a)
     (WrapHBF t f (WrapHBF t g h) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) (g :: * -> *) (h :: * -> *).
(Associative t, FunctorBy t f, FunctorBy t g, FunctorBy t h) =>
t f (t g h) <~> t (t f g) h
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
                (p (t (t f g) h a) (t (t f g) h a)
 -> p (t f (t g h) a) (t f (t g h) a))
-> (p (WrapHBF t (WrapHBF t f g) h a)
      (WrapHBF t (WrapHBF t f g) h a)
    -> p (t (t f g) h a) (t (t f g) h a))
-> p (WrapHBF t (WrapHBF t f g) h a)
     (WrapHBF t (WrapHBF t f g) h a)
-> p (t f (t g h) a) (t f (t g h) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t (t f g) h ~> WrapHBF t (WrapHBF t f g) h)
-> (WrapHBF t (WrapHBF t f g) h ~> t (t f g) h)
-> t (t f g) h <~> WrapHBF t (WrapHBF t f g) h
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (t (WrapHBF t f g) h x -> WrapHBF t (WrapHBF t f g) h 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 (t (WrapHBF t f g) h x -> WrapHBF t (WrapHBF t f g) h x)
-> (t (t f g) h x -> t (WrapHBF t f g) h x)
-> t (t f g) h x
-> WrapHBF t (WrapHBF t f g) h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t f g ~> WrapHBF t f g) -> t (t f g) h ~> t (WrapHBF t f g) h
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft t f g ~> WrapHBF t f g
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF) ((WrapHBF t f g ~> t f g) -> t (WrapHBF t f g) h ~> t (t f g) h
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (f :: k -> *)
       (j :: k -> *) (g :: k -> *).
HBifunctor t =>
(f ~> j) -> t f g ~> t j g
hleft WrapHBF t f g ~> t f g
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 (WrapHBF t f g) h x -> t (t f g) h x)
-> (WrapHBF t (WrapHBF t f g) h x -> t (WrapHBF t f g) h x)
-> WrapHBF t (WrapHBF t f g) h x
-> t (t f g) h x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t (WrapHBF t f g) h x -> t (WrapHBF t f g) h x
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 :: WrapHBF t (NonEmptyBy (WrapHBF t) f) (NonEmptyBy (WrapHBF t) f) x
-> NonEmptyBy (WrapHBF t) f x
appendNE     = t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE (t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (WrapHBF t (NonEmptyBy t f) (NonEmptyBy t f) x
    -> t (NonEmptyBy t f) (NonEmptyBy t f) x)
-> WrapHBF t (NonEmptyBy t f) (NonEmptyBy t f) x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t (NonEmptyBy t f) (NonEmptyBy t f) x
-> t (NonEmptyBy t f) (NonEmptyBy t f) x
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 :: NonEmptyBy (WrapHBF t) f
~> (f :+: WrapHBF t f (NonEmptyBy (WrapHBF t) f))
matchNE      = (t f (NonEmptyBy t f) ~> WrapHBF t f (NonEmptyBy t f))
-> (f :+: t f (NonEmptyBy t f))
   ~> (f :+: WrapHBF t f (NonEmptyBy t f))
forall k (t :: (k -> *) -> (k -> *) -> k -> *) (g :: k -> *)
       (l :: k -> *) (f :: k -> *).
HBifunctor t =>
(g ~> l) -> t f g ~> t f l
hright t f (NonEmptyBy t f) ~> WrapHBF t f (NonEmptyBy t f)
forall k k k (t :: k -> k -> k -> *) (f :: k) (g :: k) (a :: k).
t f g a -> WrapHBF t f g a
WrapHBF ((:+:) f (t f (NonEmptyBy t f)) x
 -> (:+:) f (WrapHBF t f (NonEmptyBy t f)) x)
-> (NonEmptyBy t f x -> (:+:) f (t f (NonEmptyBy t f)) x)
-> NonEmptyBy t f x
-> (:+:) f (WrapHBF t f (NonEmptyBy t f)) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyBy t f x -> (:+:) f (t f (NonEmptyBy t f)) x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
(Associative t, FunctorBy t f) =>
NonEmptyBy t f ~> (f :+: t f (NonEmptyBy t f))
matchNE
    consNE :: WrapHBF t f (NonEmptyBy (WrapHBF t) f) x
-> NonEmptyBy (WrapHBF t) f x
consNE       = t f (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f (NonEmptyBy t f) ~> NonEmptyBy t f
consNE (t f (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (WrapHBF t f (NonEmptyBy t f) x -> t f (NonEmptyBy t f) x)
-> WrapHBF t f (NonEmptyBy t f) x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t f (NonEmptyBy t f) x -> t f (NonEmptyBy t f) x
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 :: WrapHBF t f f x -> NonEmptyBy (WrapHBF t) f x
toNonEmptyBy = t f f x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t f f ~> NonEmptyBy t f
toNonEmptyBy (t f f x -> NonEmptyBy t f x)
-> (WrapHBF t f f x -> t f f x)
-> WrapHBF t f f x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t f f x -> t f f x
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 { WrapNE t f a -> NonEmptyBy t f a
unwrapNE :: NonEmptyBy t f a }

instance Functor (NonEmptyBy t f) => Functor (WrapNE t f) where
    fmap :: (a -> b) -> WrapNE t f a -> WrapNE t f b
fmap a -> b
f (WrapNE NonEmptyBy t f a
x) = NonEmptyBy t f b -> WrapNE t f b
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE ((a -> b) -> NonEmptyBy t f a -> NonEmptyBy t f b
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 :: (a -> b) -> WrapNE t f b -> WrapNE t f a
contramap a -> b
f (WrapNE NonEmptyBy t f b
x) = NonEmptyBy t f a -> WrapNE t f a
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE ((a -> b) -> NonEmptyBy t f b -> NonEmptyBy t f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f NonEmptyBy t f b
x)

instance Invariant (NonEmptyBy t f) => Invariant (WrapNE t f) where
    invmap :: (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) = NonEmptyBy t f b -> WrapNE t f b
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE ((a -> b) -> (b -> a) -> NonEmptyBy t f a -> NonEmptyBy t f b
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) x -> WrapNE t f x
biretract = NonEmptyBy t f x -> WrapNE t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
NonEmptyBy t f a -> WrapNE t f a
WrapNE (NonEmptyBy t f x -> WrapNE t f x)
-> (WrapHBF t (WrapNE t f) (WrapNE t f) x -> NonEmptyBy t f x)
-> WrapHBF t (WrapNE t f) (WrapNE t f) x
-> WrapNE t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
Associative t =>
t (NonEmptyBy t f) (NonEmptyBy t f) ~> NonEmptyBy t f
appendNE (t (NonEmptyBy t f) (NonEmptyBy t f) x -> NonEmptyBy t f x)
-> (WrapHBF t (WrapNE t f) (WrapNE t f) x
    -> t (NonEmptyBy t f) (NonEmptyBy t f) x)
-> WrapHBF t (WrapNE t f) (WrapNE t f) x
-> NonEmptyBy t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WrapNE t f ~> NonEmptyBy t f)
-> (WrapNE t f ~> NonEmptyBy t f)
-> t (WrapNE t f) (WrapNE t f)
   ~> t (NonEmptyBy t f) (NonEmptyBy t f)
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 WrapNE t f ~> NonEmptyBy t f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
WrapNE t f a -> NonEmptyBy t f a
unwrapNE WrapNE t f ~> NonEmptyBy t f
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *) a.
WrapNE t f a -> NonEmptyBy t f a
unwrapNE (t (WrapNE t f) (WrapNE t f) x
 -> t (NonEmptyBy t f) (NonEmptyBy t f) x)
-> (WrapHBF t (WrapNE t f) (WrapNE t f) x
    -> t (WrapNE t f) (WrapNE t f) x)
-> WrapHBF t (WrapNE t f) (WrapNE t f) x
-> t (NonEmptyBy t f) (NonEmptyBy t f) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WrapHBF t (WrapNE t f) (WrapNE t f) x
-> t (WrapNE t f) (WrapNE t f) x
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 :: (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 = WrapHBF t (WrapNE t f) (WrapNE t f) x -> WrapNE t f x
forall (t :: (* -> *) -> (* -> *) -> * -> *) (f :: * -> *).
SemigroupIn t f =>
t f f ~> f
biretract (WrapHBF t (WrapNE t f) (WrapNE t f) x -> WrapNE t f x)
-> (WrapHBF t g h x -> WrapHBF t (WrapNE t f) (WrapNE t f) x)
-> WrapHBF t g h x
-> WrapNE t f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (g ~> WrapNE t f)
-> (h ~> WrapNE t f)
-> WrapHBF t g h ~> WrapHBF t (WrapNE t f) (WrapNE t f)
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