-- |
-- Module      : Data.HFunctor
-- Copyright   : (c) Justin Le 2019
-- License     : BSD3
--
-- Maintainer  : justin@jle.im
-- Stability   : experimental
-- Portability : non-portable
--
-- This module provides abstractions for working with unary functor combinators.
--
-- Principally, it defines the 'HFunctor' itself, as well as some classes
-- that expose extra functionality that some 'HFunctor's have ('Inject' and
-- 'HBind').
--
-- See "Data.HFunctor.Interpret" for tools to use 'HFunctor's as functor
-- combinators that can represent interpretable schemas, and
-- "Data.HBifunctor" for an abstraction over /binary/ functor combinators.
module Data.HFunctor (
    HFunctor(..)
  , overHFunctor
  , Inject(..)
  , HBind(..)
  -- * Simple instances
  , ProxyF(..)
  , ConstF(..)
  -- * 'HFunctor' Combinators
  , HLift(..), retractHLift
  , HFree(..), foldHFree, retractHFree
  -- * Utility functions
  , injectMap
  , injectContramap
  ) where

import           Control.Applicative.Backwards
import           Control.Applicative.Free
import           Control.Applicative.Lift
import           Control.Applicative.ListF
import           Control.Applicative.Step
import           Control.Comonad.Trans.Env
import           Control.Monad.Freer.Church
import           Control.Monad.Reader
import           Control.Monad.Trans.Compose
import           Control.Monad.Trans.Identity
import           Control.Natural
import           Control.Natural.IsoF
import           Data.Coerce
import           Data.Data
import           Data.Deriving
import           Data.Functor.Bind
import           Data.Functor.Classes
import           Data.Functor.Contravariant
import           Data.Functor.Contravariant.Conclude
import           Data.Functor.Contravariant.Decide
import           Data.Functor.Contravariant.Divise
import           Data.Functor.Contravariant.Divisible
import           Data.Functor.Coyoneda
import           Data.Functor.Invariant
import           Data.Functor.Plus
import           Data.Functor.Product
import           Data.Functor.Reverse
import           Data.Functor.Sum
import           Data.Functor.These
import           Data.HFunctor.Internal
import           Data.Kind
import           Data.List.NonEmpty                   (NonEmpty(..))
import           Data.Pointed
import           Data.Semigroup.Foldable
import           GHC.Generics
import qualified Control.Alternative.Free             as Alt
import qualified Control.Applicative.Free.Fast        as FAF
import qualified Control.Applicative.Free.Final       as FA
import qualified Data.Functor.Contravariant.Coyoneda  as CCY
import qualified Data.Map                             as M
import qualified Data.Map.NonEmpty                    as NEM

-- | Lift an isomorphism over an 'HFunctor'.
--
-- Essentailly, if @f@ and @g@ are isomorphic, then so are @t f@ and @t g@.
overHFunctor
    :: HFunctor t
    => f <~> g
    -> t f <~> t g
overHFunctor :: forall {k} {k} (t :: (k -> *) -> k -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f <~> g) -> t f <~> t g
overHFunctor f <~> g
f = forall {k} (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF (forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap (forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> f ~> g
viewF f <~> g
f)) (forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap (forall {k} (f :: k -> *) (g :: k -> *). (f <~> g) -> g ~> f
reviewF f <~> g
f))

-- | The functor combinator that forgets all structure in the input.
-- Ignores the input structure and stores no information.
--
-- Acts like the "zero" with respect to functor combinator composition.
--
-- @
-- 'Control.Monad.Trans.Compose.ComposeT' ProxyF f      ~ ProxyF
-- 'Control.Monad.Trans.Compose.ComposeT' f      ProxyF ~ ProxyF
-- @
--
-- It can be 'inject'ed into (losing all information), but it is impossible
-- to ever 'Data.HFunctor.Interpret.retract' or
-- 'Data.HFunctor.Interpret.interpret' it.
--
-- This is essentially @'ConstF' ()@.
data ProxyF f a = ProxyF
  deriving (Int -> ProxyF f a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (f :: k) k (a :: k). Int -> ProxyF f a -> ShowS
forall k (f :: k) k (a :: k). [ProxyF f a] -> ShowS
forall k (f :: k) k (a :: k). ProxyF f a -> String
showList :: [ProxyF f a] -> ShowS
$cshowList :: forall k (f :: k) k (a :: k). [ProxyF f a] -> ShowS
show :: ProxyF f a -> String
$cshow :: forall k (f :: k) k (a :: k). ProxyF f a -> String
showsPrec :: Int -> ProxyF f a -> ShowS
$cshowsPrec :: forall k (f :: k) k (a :: k). Int -> ProxyF f a -> ShowS
Show, ReadPrec [ProxyF f a]
ReadPrec (ProxyF f a)
ReadS [ProxyF f a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k) k (a :: k). ReadPrec [ProxyF f a]
forall k (f :: k) k (a :: k). ReadPrec (ProxyF f a)
forall k (f :: k) k (a :: k). Int -> ReadS (ProxyF f a)
forall k (f :: k) k (a :: k). ReadS [ProxyF f a]
readListPrec :: ReadPrec [ProxyF f a]
$creadListPrec :: forall k (f :: k) k (a :: k). ReadPrec [ProxyF f a]
readPrec :: ReadPrec (ProxyF f a)
$creadPrec :: forall k (f :: k) k (a :: k). ReadPrec (ProxyF f a)
readList :: ReadS [ProxyF f a]
$creadList :: forall k (f :: k) k (a :: k). ReadS [ProxyF f a]
readsPrec :: Int -> ReadS (ProxyF f a)
$creadsPrec :: forall k (f :: k) k (a :: k). Int -> ReadS (ProxyF f a)
Read, ProxyF f a -> ProxyF f a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
/= :: ProxyF f a -> ProxyF f a -> Bool
$c/= :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
== :: ProxyF f a -> ProxyF f a -> Bool
$c== :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
Eq, ProxyF f a -> ProxyF f a -> Bool
ProxyF f a -> ProxyF f a -> Ordering
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 (f :: k) k (a :: k). Eq (ProxyF f a)
forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Ordering
forall k (f :: k) k (a :: k).
ProxyF f a -> ProxyF f a -> ProxyF f a
min :: ProxyF f a -> ProxyF f a -> ProxyF f a
$cmin :: forall k (f :: k) k (a :: k).
ProxyF f a -> ProxyF f a -> ProxyF f a
max :: ProxyF f a -> ProxyF f a -> ProxyF f a
$cmax :: forall k (f :: k) k (a :: k).
ProxyF f a -> ProxyF f a -> ProxyF f a
>= :: ProxyF f a -> ProxyF f a -> Bool
$c>= :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
> :: ProxyF f a -> ProxyF f a -> Bool
$c> :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
<= :: ProxyF f a -> ProxyF f a -> Bool
$c<= :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
< :: ProxyF f a -> ProxyF f a -> Bool
$c< :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Bool
compare :: ProxyF f a -> ProxyF f a -> Ordering
$ccompare :: forall k (f :: k) k (a :: k). ProxyF f a -> ProxyF f a -> Ordering
Ord, forall k (f :: k) a b. a -> ProxyF f b -> ProxyF f a
forall k (f :: k) a b. (a -> b) -> ProxyF f a -> ProxyF f b
forall a b. (a -> b) -> ProxyF f a -> ProxyF f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ProxyF f b -> ProxyF f a
$c<$ :: forall k (f :: k) a b. a -> ProxyF f b -> ProxyF f a
fmap :: forall a b. (a -> b) -> ProxyF f a -> ProxyF f b
$cfmap :: forall k (f :: k) a b. (a -> b) -> ProxyF f a -> ProxyF f b
Functor, forall k (f :: k) a. Eq a => a -> ProxyF f a -> Bool
forall k (f :: k) a. Num a => ProxyF f a -> a
forall k (f :: k) a. Ord a => ProxyF f a -> a
forall k (f :: k) m. Monoid m => ProxyF f m -> m
forall k (f :: k) a. ProxyF f a -> Bool
forall k (f :: k) a. ProxyF f a -> Int
forall k (f :: k) a. ProxyF f a -> [a]
forall k (f :: k) a. (a -> a -> a) -> ProxyF f a -> a
forall k (f :: k) m a. Monoid m => (a -> m) -> ProxyF f a -> m
forall k (f :: k) b a. (b -> a -> b) -> b -> ProxyF f a -> b
forall k (f :: k) a b. (a -> b -> b) -> b -> ProxyF f a -> b
forall m a. Monoid m => (a -> m) -> ProxyF f a -> m
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ProxyF f a -> a
$cproduct :: forall k (f :: k) a. Num a => ProxyF f a -> a
sum :: forall a. Num a => ProxyF f a -> a
$csum :: forall k (f :: k) a. Num a => ProxyF f a -> a
minimum :: forall a. Ord a => ProxyF f a -> a
$cminimum :: forall k (f :: k) a. Ord a => ProxyF f a -> a
maximum :: forall a. Ord a => ProxyF f a -> a
$cmaximum :: forall k (f :: k) a. Ord a => ProxyF f a -> a
elem :: forall a. Eq a => a -> ProxyF f a -> Bool
$celem :: forall k (f :: k) a. Eq a => a -> ProxyF f a -> Bool
length :: forall a. ProxyF f a -> Int
$clength :: forall k (f :: k) a. ProxyF f a -> Int
null :: forall a. ProxyF f a -> Bool
$cnull :: forall k (f :: k) a. ProxyF f a -> Bool
toList :: forall a. ProxyF f a -> [a]
$ctoList :: forall k (f :: k) a. ProxyF f a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ProxyF f a -> a
$cfoldl1 :: forall k (f :: k) a. (a -> a -> a) -> ProxyF f a -> a
foldr1 :: forall a. (a -> a -> a) -> ProxyF f a -> a
$cfoldr1 :: forall k (f :: k) a. (a -> a -> a) -> ProxyF f a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ProxyF f a -> b
$cfoldl' :: forall k (f :: k) b a. (b -> a -> b) -> b -> ProxyF f a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ProxyF f a -> b
$cfoldl :: forall k (f :: k) b a. (b -> a -> b) -> b -> ProxyF f a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ProxyF f a -> b
$cfoldr' :: forall k (f :: k) a b. (a -> b -> b) -> b -> ProxyF f a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ProxyF f a -> b
$cfoldr :: forall k (f :: k) a b. (a -> b -> b) -> b -> ProxyF f a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ProxyF f a -> m
$cfoldMap' :: forall k (f :: k) m a. Monoid m => (a -> m) -> ProxyF f a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ProxyF f a -> m
$cfoldMap :: forall k (f :: k) m a. Monoid m => (a -> m) -> ProxyF f a -> m
fold :: forall m. Monoid m => ProxyF f m -> m
$cfold :: forall k (f :: k) m. Monoid m => ProxyF f m -> m
Foldable, forall k (f :: k). Functor (ProxyF f)
forall k (f :: k). Foldable (ProxyF f)
forall k (f :: k) (m :: * -> *) a.
Monad m =>
ProxyF f (m a) -> m (ProxyF f a)
forall k (f :: k) (f :: * -> *) a.
Applicative f =>
ProxyF f (f a) -> f (ProxyF f a)
forall k (f :: k) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ProxyF f a -> m (ProxyF f b)
forall k (f :: k) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
sequence :: forall (m :: * -> *) a. Monad m => ProxyF f (m a) -> m (ProxyF f a)
$csequence :: forall k (f :: k) (m :: * -> *) a.
Monad m =>
ProxyF f (m a) -> m (ProxyF f a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ProxyF f a -> m (ProxyF f b)
$cmapM :: forall k (f :: k) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ProxyF f a -> m (ProxyF f b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
ProxyF f (f a) -> f (ProxyF f a)
$csequenceA :: forall k (f :: k) (f :: * -> *) a.
Applicative f =>
ProxyF f (f a) -> f (ProxyF f a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
$ctraverse :: forall k (f :: k) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
Traversable, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (f :: k) k (a :: k) x. Rep (ProxyF f a) x -> ProxyF f a
forall k (f :: k) k (a :: k) x. ProxyF f a -> Rep (ProxyF f a) x
$cto :: forall k (f :: k) k (a :: k) x. Rep (ProxyF f a) x -> ProxyF f a
$cfrom :: forall k (f :: k) k (a :: k) x. ProxyF f a -> Rep (ProxyF f a) x
Generic, ProxyF f a -> DataType
ProxyF f a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall {k} {f :: k} {k} {a :: k}.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
Typeable (ProxyF f a)
forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
ProxyF f a -> DataType
forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
ProxyF f a -> Constr
forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall b. Data b => b -> b) -> ProxyF f a -> ProxyF f a
forall k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
Int -> (forall d. Data d => d -> u) -> ProxyF f a -> u
forall k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall d. Data d => d -> u) -> ProxyF f a -> [u]
forall k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
forall k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
forall k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Monad m) =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
forall k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
forall k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ProxyF f a)
forall k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ProxyF f a -> c (ProxyF f a)
forall k (f :: k) k (a :: k) (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ProxyF f a))
forall k (f :: k) k (a :: k) (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ProxyF f a))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ProxyF f a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ProxyF f a -> c (ProxyF f a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
$cgmapMo :: forall k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
$cgmapMp :: forall k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
$cgmapM :: forall k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Monad m) =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ProxyF f a -> u
$cgmapQi :: forall k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
Int -> (forall d. Data d => d -> u) -> ProxyF f a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ProxyF f a -> [u]
$cgmapQ :: forall k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall d. Data d => d -> u) -> ProxyF f a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
$cgmapQr :: forall k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
$cgmapQl :: forall k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
gmapT :: (forall b. Data b => b -> b) -> ProxyF f a -> ProxyF f a
$cgmapT :: forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall b. Data b => b -> b) -> ProxyF f a -> ProxyF f a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ProxyF f a))
$cdataCast2 :: forall k (f :: k) k (a :: k) (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ProxyF f a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ProxyF f a))
$cdataCast1 :: forall k (f :: k) k (a :: k) (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ProxyF f a))
dataTypeOf :: ProxyF f a -> DataType
$cdataTypeOf :: forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
ProxyF f a -> DataType
toConstr :: ProxyF f a -> Constr
$ctoConstr :: forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
ProxyF f a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ProxyF f a)
$cgunfold :: forall k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ProxyF f a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ProxyF f a -> c (ProxyF f a)
$cgfoldl :: forall k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ProxyF f a -> c (ProxyF f a)
Data)

deriveShow1 ''ProxyF
deriveRead1 ''ProxyF
deriveEq1 ''ProxyF
deriveOrd1 ''ProxyF

-- | @since 0.3.0.0
instance Contravariant (ProxyF f) where
    contramap :: forall a' a. (a' -> a) -> ProxyF f a -> ProxyF f a'
contramap a' -> a
_ = coerce :: forall a b. Coercible a b => a -> b
coerce
-- | @since 0.3.0.0
instance Divisible (ProxyF f) where
    divide :: forall a b c.
(a -> (b, c)) -> ProxyF f b -> ProxyF f c -> ProxyF f a
divide a -> (b, c)
_ ProxyF f b
_ ProxyF f c
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
    conquer :: forall a. ProxyF f a
conquer = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
-- | @since 0.3.0.0
instance Divise (ProxyF f) where
    divise :: forall a b c.
(a -> (b, c)) -> ProxyF f b -> ProxyF f c -> ProxyF f a
divise a -> (b, c)
_ ProxyF f b
_ ProxyF f c
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
-- | @since 0.3.0.0
instance Decide (ProxyF f) where
    decide :: forall a b c.
(a -> Either b c) -> ProxyF f b -> ProxyF f c -> ProxyF f a
decide a -> Either b c
_ ProxyF f b
_ ProxyF f c
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
-- | @since 0.3.0.0
instance Conclude (ProxyF f) where
    conclude :: forall a. (a -> Void) -> ProxyF f a
conclude a -> Void
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
-- | @since 0.3.0.0
instance Decidable (ProxyF f) where
    choose :: forall a b c.
(a -> Either b c) -> ProxyF f b -> ProxyF f c -> ProxyF f a
choose a -> Either b c
_ ProxyF f b
_ ProxyF f c
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
    lose :: forall a. (a -> Void) -> ProxyF f a
lose a -> Void
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF
-- | @since 0.3.0.0
instance Invariant (ProxyF f) where
    invmap :: forall a b. (a -> b) -> (b -> a) -> ProxyF f a -> ProxyF f b
invmap a -> b
_ b -> a
_ = coerce :: forall a b. Coercible a b => a -> b
coerce

instance HFunctor ProxyF where
    hmap :: forall (f :: k -> *) (g :: k -> *).
(f ~> g) -> ProxyF f ~> ProxyF g
hmap f ~> g
_ = coerce :: forall a b. Coercible a b => a -> b
coerce

-- | Functor combinator that forgets all structure on the input, and
-- instead stores a value of type @e@.
--
-- Like 'ProxyF', acts like a "zero" with functor combinator composition.
--
-- It can be 'inject'ed into (losing all information), but it is impossible
-- to ever 'Data.HFunctor.Interpret.retract' or
-- 'Data.HFunctor.Interpret.interpret' it.
data ConstF e f a = ConstF { forall {k} {k} e (f :: k) (a :: k). ConstF e f a -> e
getConstF :: e }
  deriving (Int -> ConstF e f a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall e k (f :: k) k (a :: k).
Show e =>
Int -> ConstF e f a -> ShowS
forall e k (f :: k) k (a :: k). Show e => [ConstF e f a] -> ShowS
forall e k (f :: k) k (a :: k). Show e => ConstF e f a -> String
showList :: [ConstF e f a] -> ShowS
$cshowList :: forall e k (f :: k) k (a :: k). Show e => [ConstF e f a] -> ShowS
show :: ConstF e f a -> String
$cshow :: forall e k (f :: k) k (a :: k). Show e => ConstF e f a -> String
showsPrec :: Int -> ConstF e f a -> ShowS
$cshowsPrec :: forall e k (f :: k) k (a :: k).
Show e =>
Int -> ConstF e f a -> ShowS
Show, ReadPrec [ConstF e f a]
ReadPrec (ConstF e f a)
ReadS [ConstF e f a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall e k (f :: k) k (a :: k). Read e => ReadPrec [ConstF e f a]
forall e k (f :: k) k (a :: k). Read e => ReadPrec (ConstF e f a)
forall e k (f :: k) k (a :: k).
Read e =>
Int -> ReadS (ConstF e f a)
forall e k (f :: k) k (a :: k). Read e => ReadS [ConstF e f a]
readListPrec :: ReadPrec [ConstF e f a]
$creadListPrec :: forall e k (f :: k) k (a :: k). Read e => ReadPrec [ConstF e f a]
readPrec :: ReadPrec (ConstF e f a)
$creadPrec :: forall e k (f :: k) k (a :: k). Read e => ReadPrec (ConstF e f a)
readList :: ReadS [ConstF e f a]
$creadList :: forall e k (f :: k) k (a :: k). Read e => ReadS [ConstF e f a]
readsPrec :: Int -> ReadS (ConstF e f a)
$creadsPrec :: forall e k (f :: k) k (a :: k).
Read e =>
Int -> ReadS (ConstF e f a)
Read, ConstF e f a -> ConstF e f a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall e k (f :: k) k (a :: k).
Eq e =>
ConstF e f a -> ConstF e f a -> Bool
/= :: ConstF e f a -> ConstF e f a -> Bool
$c/= :: forall e k (f :: k) k (a :: k).
Eq e =>
ConstF e f a -> ConstF e f a -> Bool
== :: ConstF e f a -> ConstF e f a -> Bool
$c== :: forall e k (f :: k) k (a :: k).
Eq e =>
ConstF e f a -> ConstF e f a -> Bool
Eq, ConstF e f a -> ConstF e f a -> Bool
ConstF e f a -> ConstF e f a -> Ordering
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 {e} {k} {f :: k} {k} {a :: k}. Ord e => Eq (ConstF e f a)
forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Bool
forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Ordering
forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> ConstF e f a
min :: ConstF e f a -> ConstF e f a -> ConstF e f a
$cmin :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> ConstF e f a
max :: ConstF e f a -> ConstF e f a -> ConstF e f a
$cmax :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> ConstF e f a
>= :: ConstF e f a -> ConstF e f a -> Bool
$c>= :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Bool
> :: ConstF e f a -> ConstF e f a -> Bool
$c> :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Bool
<= :: ConstF e f a -> ConstF e f a -> Bool
$c<= :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Bool
< :: ConstF e f a -> ConstF e f a -> Bool
$c< :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Bool
compare :: ConstF e f a -> ConstF e f a -> Ordering
$ccompare :: forall e k (f :: k) k (a :: k).
Ord e =>
ConstF e f a -> ConstF e f a -> Ordering
Ord, forall a b. (a -> b) -> ConstF e f a -> ConstF e f b
forall e k (f :: k) a b. a -> ConstF e f b -> ConstF e f a
forall e k (f :: k) a b. (a -> b) -> ConstF e f a -> ConstF e f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> ConstF e f b -> ConstF e f a
$c<$ :: forall e k (f :: k) a b. a -> ConstF e f b -> ConstF e f a
fmap :: forall a b. (a -> b) -> ConstF e f a -> ConstF e f b
$cfmap :: forall e k (f :: k) a b. (a -> b) -> ConstF e f a -> ConstF e f b
Functor, forall m a. Monoid m => (a -> m) -> ConstF e f a -> m
forall e k (f :: k) a. Eq a => a -> ConstF e f a -> Bool
forall e k (f :: k) a. Num a => ConstF e f a -> a
forall e k (f :: k) a. Ord a => ConstF e f a -> a
forall e k (f :: k) m. Monoid m => ConstF e f m -> m
forall e k (f :: k) a. ConstF e f a -> Bool
forall e k (f :: k) a. ConstF e f a -> Int
forall e k (f :: k) a. ConstF e f a -> [a]
forall e k (f :: k) a. (a -> a -> a) -> ConstF e f a -> a
forall e k (f :: k) m a. Monoid m => (a -> m) -> ConstF e f a -> m
forall e k (f :: k) b a. (b -> a -> b) -> b -> ConstF e f a -> b
forall e k (f :: k) a b. (a -> b -> b) -> b -> ConstF e f a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => ConstF e f a -> a
$cproduct :: forall e k (f :: k) a. Num a => ConstF e f a -> a
sum :: forall a. Num a => ConstF e f a -> a
$csum :: forall e k (f :: k) a. Num a => ConstF e f a -> a
minimum :: forall a. Ord a => ConstF e f a -> a
$cminimum :: forall e k (f :: k) a. Ord a => ConstF e f a -> a
maximum :: forall a. Ord a => ConstF e f a -> a
$cmaximum :: forall e k (f :: k) a. Ord a => ConstF e f a -> a
elem :: forall a. Eq a => a -> ConstF e f a -> Bool
$celem :: forall e k (f :: k) a. Eq a => a -> ConstF e f a -> Bool
length :: forall a. ConstF e f a -> Int
$clength :: forall e k (f :: k) a. ConstF e f a -> Int
null :: forall a. ConstF e f a -> Bool
$cnull :: forall e k (f :: k) a. ConstF e f a -> Bool
toList :: forall a. ConstF e f a -> [a]
$ctoList :: forall e k (f :: k) a. ConstF e f a -> [a]
foldl1 :: forall a. (a -> a -> a) -> ConstF e f a -> a
$cfoldl1 :: forall e k (f :: k) a. (a -> a -> a) -> ConstF e f a -> a
foldr1 :: forall a. (a -> a -> a) -> ConstF e f a -> a
$cfoldr1 :: forall e k (f :: k) a. (a -> a -> a) -> ConstF e f a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> ConstF e f a -> b
$cfoldl' :: forall e k (f :: k) b a. (b -> a -> b) -> b -> ConstF e f a -> b
foldl :: forall b a. (b -> a -> b) -> b -> ConstF e f a -> b
$cfoldl :: forall e k (f :: k) b a. (b -> a -> b) -> b -> ConstF e f a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> ConstF e f a -> b
$cfoldr' :: forall e k (f :: k) a b. (a -> b -> b) -> b -> ConstF e f a -> b
foldr :: forall a b. (a -> b -> b) -> b -> ConstF e f a -> b
$cfoldr :: forall e k (f :: k) a b. (a -> b -> b) -> b -> ConstF e f a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> ConstF e f a -> m
$cfoldMap' :: forall e k (f :: k) m a. Monoid m => (a -> m) -> ConstF e f a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> ConstF e f a -> m
$cfoldMap :: forall e k (f :: k) m a. Monoid m => (a -> m) -> ConstF e f a -> m
fold :: forall m. Monoid m => ConstF e f m -> m
$cfold :: forall e k (f :: k) m. Monoid m => ConstF e f m -> m
Foldable, forall e k (f :: k). Functor (ConstF e f)
forall e k (f :: k). Foldable (ConstF e f)
forall e k (f :: k) (m :: * -> *) a.
Monad m =>
ConstF e f (m a) -> m (ConstF e f a)
forall e k (f :: k) (f :: * -> *) a.
Applicative f =>
ConstF e f (f a) -> f (ConstF e f a)
forall e k (f :: k) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConstF e f a -> m (ConstF e f b)
forall e k (f :: k) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
sequence :: forall (m :: * -> *) a.
Monad m =>
ConstF e f (m a) -> m (ConstF e f a)
$csequence :: forall e k (f :: k) (m :: * -> *) a.
Monad m =>
ConstF e f (m a) -> m (ConstF e f a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConstF e f a -> m (ConstF e f b)
$cmapM :: forall e k (f :: k) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConstF e f a -> m (ConstF e f b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
ConstF e f (f a) -> f (ConstF e f a)
$csequenceA :: forall e k (f :: k) (f :: * -> *) a.
Applicative f =>
ConstF e f (f a) -> f (ConstF e f a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
$ctraverse :: forall e k (f :: k) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
Traversable, Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall e k (f :: k) k (a :: k) x.
Rep (ConstF e f a) x -> ConstF e f a
forall e k (f :: k) k (a :: k) x.
ConstF e f a -> Rep (ConstF e f a) x
$cto :: forall e k (f :: k) k (a :: k) x.
Rep (ConstF e f a) x -> ConstF e f a
$cfrom :: forall e k (f :: k) k (a :: k) x.
ConstF e f a -> Rep (ConstF e f a) x
Generic, ConstF e f a -> DataType
ConstF e f a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall {e} {k} {f :: k} {k} {a :: k}.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
Typeable (ConstF e f a)
forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
ConstF e f a -> DataType
forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
ConstF e f a -> Constr
forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall b. Data b => b -> b) -> ConstF e f a -> ConstF e f a
forall e k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
Int -> (forall d. Data d => d -> u) -> ConstF e f a -> u
forall e k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall d. Data d => d -> u) -> ConstF e f a -> [u]
forall e k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
forall e k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
forall e k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Monad m) =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
forall e k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
forall e k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConstF e f a)
forall e k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstF e f a -> c (ConstF e f a)
forall e k (f :: k) k (a :: k) (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ConstF e f a))
forall e k (f :: k) k (a :: k) (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConstF e f a))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConstF e f a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstF e f a -> c (ConstF e f a)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
$cgmapMo :: forall e k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
$cgmapMp :: forall e k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
$cgmapM :: forall e k (f :: k) k (a :: k) (m :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Monad m) =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConstF e f a -> u
$cgmapQi :: forall e k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
Int -> (forall d. Data d => d -> u) -> ConstF e f a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ConstF e f a -> [u]
$cgmapQ :: forall e k (f :: k) k (a :: k) u.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall d. Data d => d -> u) -> ConstF e f a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
$cgmapQr :: forall e k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
$cgmapQl :: forall e k (f :: k) k (a :: k) r r'.
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
gmapT :: (forall b. Data b => b -> b) -> ConstF e f a -> ConstF e f a
$cgmapT :: forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall b. Data b => b -> b) -> ConstF e f a -> ConstF e f a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConstF e f a))
$cdataCast2 :: forall e k (f :: k) k (a :: k) (t :: * -> * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConstF e f a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ConstF e f a))
$cdataCast1 :: forall e k (f :: k) k (a :: k) (t :: * -> *) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e,
 Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ConstF e f a))
dataTypeOf :: ConstF e f a -> DataType
$cdataTypeOf :: forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
ConstF e f a -> DataType
toConstr :: ConstF e f a -> Constr
$ctoConstr :: forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
ConstF e f a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConstF e f a)
$cgunfold :: forall e k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConstF e f a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstF e f a -> c (ConstF e f a)
$cgfoldl :: forall e k (f :: k) k (a :: k) (c :: * -> *).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConstF e f a -> c (ConstF e f a)
Data)

deriveShow1 ''ConstF
deriveRead1 ''ConstF
deriveEq1 ''ConstF
deriveOrd1 ''ConstF

-- | @since 0.3.0.0
instance Contravariant (ConstF e f) where
    contramap :: forall a' a. (a' -> a) -> ConstF e f a -> ConstF e f a'
contramap a' -> a
_ = coerce :: forall a b. Coercible a b => a -> b
coerce
-- | @since 0.3.0.0
instance Monoid e => Divisible (ConstF e f) where
    divide :: forall a b c.
(a -> (b, c)) -> ConstF e f b -> ConstF e f c -> ConstF e f a
divide a -> (b, c)
_ (ConstF e
x) (ConstF e
y) = forall {k} {k} e (f :: k) (a :: k). e -> ConstF e f a
ConstF (e
x forall a. Semigroup a => a -> a -> a
<> e
y)
    conquer :: forall a. ConstF e f a
conquer = forall {k} {k} e (f :: k) (a :: k). e -> ConstF e f a
ConstF forall a. Monoid a => a
mempty
-- | @since 0.3.0.0
instance Semigroup e => Divise (ConstF e f) where
    divise :: forall a b c.
(a -> (b, c)) -> ConstF e f b -> ConstF e f c -> ConstF e f a
divise a -> (b, c)
_ (ConstF e
x) (ConstF e
y) = forall {k} {k} e (f :: k) (a :: k). e -> ConstF e f a
ConstF (e
x forall a. Semigroup a => a -> a -> a
<> e
y)
-- | @since 0.3.0.0
instance Invariant (ConstF e f) where
    invmap :: forall a b. (a -> b) -> (b -> a) -> ConstF e f a -> ConstF e f b
invmap a -> b
_ b -> a
_ = coerce :: forall a b. Coercible a b => a -> b
coerce

instance HFunctor (ConstF e) where
    hmap :: forall (f :: k -> *) (g :: k -> *).
(f ~> g) -> ConstF e f ~> ConstF e g
hmap f ~> g
_ = coerce :: forall a b. Coercible a b => a -> b
coerce

-- | An "'HFunctor' combinator" that enhances an 'HFunctor' with the
-- ability to hold a single @f a@.  This is the higher-order analogue of
-- 'Control.Applicative.Lift.Lift'.
--
-- You can think of it as a free 'Inject' for any @f@.
--
-- Note that @'HLift' 'IdentityT'@ is equivalent to @'EnvT'
-- 'Data.Semigroup.Any'@.
data HLift t f a = HPure  (f a)
                 | HOther (t f a)
  deriving forall a b. a -> HLift t f b -> HLift t f a
forall a b. (a -> b) -> HLift t f a -> HLift t f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Functor f, Functor (t f)) =>
a -> HLift t f b -> HLift t f a
forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Functor f, Functor (t f)) =>
(a -> b) -> HLift t f a -> HLift t f b
<$ :: forall a b. a -> HLift t f b -> HLift t f a
$c<$ :: forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Functor f, Functor (t f)) =>
a -> HLift t f b -> HLift t f a
fmap :: forall a b. (a -> b) -> HLift t f a -> HLift t f b
$cfmap :: forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Functor f, Functor (t f)) =>
(a -> b) -> HLift t f a -> HLift t f b
Functor

instance (Show1 (t f), Show1 f) => Show1 (HLift t f) where
    liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> HLift t f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d = \case
      HPure f a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"HPure" Int
d f a
x
      HOther t f a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"HOther" Int
d t f a
x

deriving instance (Show (f a), Show (t f a)) => Show (HLift t f a)
deriving instance (Read (f a), Read (t f a)) => Read (HLift t f a)
deriving instance (Eq (f a), Eq (t f a)) => Eq (HLift t f a)
deriving instance (Ord (f a), Ord (t f a)) => Ord (HLift t f a)

instance (Eq1 (t f), Eq1 f) => Eq1 (HLift t f) where
    liftEq :: forall a b. (a -> b -> Bool) -> HLift t f a -> HLift t f b -> Bool
liftEq a -> b -> Bool
eq = \case
      HPure  f a
x -> \case
        HPure  f b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq f a
x f b
y
        HOther t f b
_ -> Bool
False
      HOther t f a
x -> \case
        HPure  f b
_ -> Bool
False
        HOther t f b
y -> forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq t f a
x t f b
y

instance (Ord1 (t f), Ord1 f) => Ord1 (HLift t f) where
    liftCompare :: forall a b.
(a -> b -> Ordering) -> HLift t f a -> HLift t f b -> Ordering
liftCompare a -> b -> Ordering
c = \case
      HPure  f a
x -> \case
        HPure  f b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c f a
x f b
y
        HOther t f b
_ -> Ordering
LT
      HOther t f a
x -> \case
        HPure  f b
_ -> Ordering
GT
        HOther t f b
y -> forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
c t f a
x t f b
y

instance HFunctor t => HFunctor (HLift t) where
    hmap :: forall (f :: k1 -> *) (g :: k1 -> *).
(f ~> g) -> HLift t f ~> HLift t g
hmap f ~> g
f = \case
      HPure  f x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  (f ~> g
f f x
x)
      HOther t f x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther (forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap f ~> g
f t f x
x)

-- | @since 0.3.0.0
instance (Contravariant f, Contravariant (t f)) => Contravariant (HLift t f) where
    contramap :: forall a' a. (a' -> a) -> HLift t f a -> HLift t f a'
contramap a' -> a
f = \case
      HPure  f a
x  -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f f a
x)
      HOther t f a
xs -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f t f a
xs)

-- | @since 0.3.0.0
instance (Invariant f, Invariant (t f)) => Invariant (HLift t f) where
    invmap :: forall a b. (a -> b) -> (b -> a) -> HLift t f a -> HLift t f b
invmap a -> b
f b -> a
g = \case
      HPure  f a
x  -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x)
      HOther t f a
xs -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g t f a
xs)

-- | A higher-level 'Data.HFunctor.Interpret.retract' to get a @t f a@ back
-- out of an @'HLift' t f a@, provided @t@ is an instance of 'Inject'.
--
-- This witnesses the fact that 'HLift' is the "Free 'Inject'".
retractHLift
    :: Inject t
    => HLift t f a
    -> t f a
retractHLift :: forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
Inject t =>
HLift t f a -> t f a
retractHLift = \case
    HPure  f a
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f a
x
    HOther t f a
x -> t f a
x

-- | An "'HFunctor' combinator" that turns an 'HFunctor' into potentially
-- infinite nestings of that 'HFunctor'.
--
-- An @'HFree' t f a@ is either @f a@, @t f a@, @t (t f) a@, @t (t (t f))
-- a@, etc.
--
-- This effectively turns @t@ into a tree with @t@ branches.
--
-- One particularly useful usage is with 'MapF'.  For example if you had
-- a data type representing a command line command parser:
--
-- @
-- data Command a
-- @
--
-- You could represent "many possible named commands" using
--
-- @
-- type Commands = 'MapF' 'String' Command
-- @
--
-- And you can represent multiple /nested/ named commands using:
--
-- @
-- type NestedCommands = 'HFree' ('MapF' 'String')
-- @
--
-- This has an 'Data.HFunctor.Interpret.Interpret' instance, but it can be
-- more useful to use via direct pattern matching, or through
--
-- @
-- 'foldHFree'
--     :: 'HBifunctor' t
--     => f '~>' g
--     -> t g ~> g
--     -> HFree t f ~> g
-- @
--
-- which requires no extra constriant on @g@, and lets you consider each
-- branch separately.
--
-- This can be considered the higher-oder analogue of
-- 'Control.Monad.Free.Free'; it is the free 'HBind' for any @'HFunctor'
-- t@.
--
-- Note that @'HFree' 'IdentityT'@ is equivalent to 'Step'.
data HFree t f a = HReturn (f a)
                 | HJoin   (t (HFree t f) a)

deriving instance (Functor f, Functor (t (HFree t f))) => Functor (HFree t f)

instance (Contravariant f, Contravariant (t (HFree t f))) => Contravariant (HFree t f) where
    contramap :: forall a' a. (a' -> a) -> HFree t f a -> HFree t f a'
contramap a' -> a
f = \case
      HReturn f a
x  -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f f a
x)
      HJoin   t (HFree t f) a
xs -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin   (forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a' -> a
f t (HFree t f) a
xs)

instance (Invariant f, Invariant (t (HFree t f))) => Invariant (HFree t f) where
    invmap :: forall a b. (a -> b) -> (b -> a) -> HFree t f a -> HFree t f b
invmap a -> b
f b -> a
g = \case
      HReturn f a
x  -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g f a
x)
      HJoin   t (HFree t f) a
xs -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin   (forall (f :: * -> *) a b.
Invariant f =>
(a -> b) -> (b -> a) -> f a -> f b
invmap a -> b
f b -> a
g t (HFree t f) a
xs)

-- | Recursively fold down an 'HFree' into a single @g@ result, by handling
-- each branch.  Can be more useful than
-- 'Data.HFunctor.Interpret.interpret' because it allows you to treat each
-- branch separately, and also does not require any constraint on @g@.
--
-- This is the catamorphism on 'HFree'.
foldHFree
    :: forall t f g. HFunctor t
    => (f ~> g)
    -> (t g ~> g)
    -> (HFree t f ~> g)
foldHFree :: forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HFunctor t =>
(f ~> g) -> (t g ~> g) -> HFree t f ~> g
foldHFree f ~> g
f t g ~> g
g = HFree t f ~> g
go
  where
    go :: HFree t f ~> g
    go :: HFree t f ~> g
go (HReturn f x
x) = f ~> g
f f x
x
    go (HJoin   t (HFree t f) x
x) = t g ~> g
g (forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap HFree t f ~> g
go t (HFree t f) x
x)

-- | A higher-level 'Data.HFunctor.Interpret.retract' to get a @t f a@ back
-- out of an @'HFree' t f a@, provided @t@ is an instance of 'Bind'.
--
-- This witnesses the fact that 'HFree' is the "Free 'Bind'".
retractHFree
    :: HBind t
    => HFree t f a
    -> t f a
retractHFree :: forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
HBind t =>
HFree t f a -> t f a
retractHFree = \case
    HReturn f a
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f a
x
    HJoin   t (HFree t f) a
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
HBind t =>
HFree t f a -> t f a
retractHFree t (HFree t f) a
x

instance (Show1 (t (HFree t f)), Show1 f) => Show1 (HFree t f) where
    liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> HFree t f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d = \case
      HReturn f a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"HReturn" Int
d f a
x
      HJoin   t (HFree t f) a
x -> forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith (forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) String
"HJoin"   Int
d t (HFree t f) a
x

instance (Show1 (t (HFree t f)), Show1 f, Show a) => Show (HFree t f a) where
    showsPrec :: Int -> HFree t f a -> ShowS
showsPrec = forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec forall a. Show a => Int -> a -> ShowS
showsPrec forall a. Show a => [a] -> ShowS
showList

instance HFunctor t => HFunctor (HFree t) where
    hmap :: forall f g. (f ~> g) -> HFree t f ~> HFree t g
    hmap :: forall (f :: k1 -> *) (g :: k1 -> *).
(f ~> g) -> HFree t f ~> HFree t g
hmap f ~> g
f = HFree t f ~> HFree t g
go
      where
        go :: HFree t f ~> HFree t g
        go :: HFree t f ~> HFree t g
go = \case
          HReturn f x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn (f ~> g
f f x
x)
          HJoin   t (HFree t f) x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin (forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap HFree t f ~> HFree t g
go t (HFree t f) x
x)

-- | A typeclass for 'HFunctor's where you can "inject" an @f a@ into a @t
-- f a@:
--
-- @
-- 'inject' :: f a -> t f a
-- @
--
-- If you think of @t f a@ as an "enhanced @f@", then 'inject' allows you
-- to use an @f@ as its enhanced form.
--
-- With the exception of directly pattern matching on the result, 'inject'
-- itself is not too useful in the general case without
-- 'Data.HFunctor.Interpret.Interpret' to allow us to interpret or retrieve
-- back the @f@.
class HFunctor t => Inject t where
    -- | Lift from @f@ into the enhanced @t f@ structure.  Analogous to
    -- 'lift' from 'MonadTrans'.
    --
    -- Note that this lets us "lift" a @f a@; if you want to lift an @a@
    -- with @a -> t f a@, check if @t f@ is an instance of 'Applicative' or
    -- 'Pointed'.
    inject :: f ~> t f

    {-# MINIMAL inject #-}

-- | A useful wrapper over the common pattern of
-- fmap-before-inject/inject-and-fmap.
--
-- @since 0.3.3.0
injectMap :: (Inject t, Functor f) => (a -> b) -> f a -> t f b
injectMap :: forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Inject t, Functor f) =>
(a -> b) -> f a -> t f b
injectMap a -> b
f = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f

-- | A useful wrapper over the common pattern of
-- contramap-before-inject/inject-and-contramap.
--
-- @since 0.3.3.0
injectContramap :: (Inject t, Contravariant f) => (a -> b) -> f b -> t f a
injectContramap :: forall (t :: (* -> *) -> * -> *) (f :: * -> *) a b.
(Inject t, Contravariant f) =>
(a -> b) -> f b -> t f a
injectContramap a -> b
f = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a' a.
Contravariant f =>
(a' -> a) -> f a -> f a'
contramap a -> b
f

-- | 'HBind' is effectively a "higher-order 'Monad'", in the sense that
-- 'HFunctor' is a "higher-order 'Functor'".
--
-- It can be considered a typeclass for 'HFunctor's that you can bind
-- continuations to, nautral/universal over all @f@/functors. They work
-- "for all functors" you lift, without requiring any constraints.
--
-- It is very similar to 'Data.HFunctor.Interpret.Interpret', except
-- 'Data.HFunctor.Interpret.Interpret' has the ability to constrain the
-- contexts to some typeclass.
--
-- The main law is that binding 'inject' should leave things unchanged:
--
-- @
-- 'hbind' 'inject' == 'id'
-- @
--
-- But 'hbind' should also be associatiatve, in a way that makes
--
-- @
-- 'hjoin' . hjoin
--    = hjoin . 'hmap' hjoin
-- @
--
-- That is, squishing a @t (t (t f)) a@ into a @t f a@ can be done "inside"
-- first, then "outside", or "outside" first, then "inside".
--
-- Note that these laws are different from the
-- 'Data.HFunctor.Interpret.Interpret' laws, so we often have instances
-- where 'hbind' and 'Data.HFunctor.Interpret.interpret' (though they both
-- may typecheck) produce different behavior.
--
-- This class is similar to 'Control.Monad.Morph.MMonad' from
-- "Control.Monad.Morph", but instances must work without a 'Monad' constraint.
class Inject t => HBind t where
    -- | Bind a continuation to a @t f@ into some context @g@.
    hbind :: (f ~> t g) -> t f ~> t g
    hbind f ~> t g
f = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
HBind t =>
t (t f) ~> t f
hjoin forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap f ~> t g
f

    -- | Collapse a nested @t (t f)@ into a single @t f@.
    hjoin :: t (t f) ~> t f
    hjoin = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind forall a. a -> a
id
    {-# MINIMAL hbind | hjoin #-}

instance Inject Coyoneda where
    inject :: forall (f :: * -> *). f ~> Coyoneda f
inject = forall (f :: * -> *). f ~> Coyoneda f
liftCoyoneda

-- | @since 0.3.0.0
instance Inject CCY.Coyoneda where
    inject :: forall (f :: * -> *). f ~> Coyoneda f
inject = forall (f :: * -> *). f ~> Coyoneda f
CCY.liftCoyoneda

instance Inject Ap where
    inject :: forall (f :: * -> *). f ~> Ap f
inject = forall (f :: * -> *). f ~> Ap f
liftAp

instance Inject ListF where
    inject :: forall (f :: k -> *). f ~> ListF f
inject = forall {k} (f :: k -> *) (a :: k). [f a] -> ListF f a
ListF forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> [a]
:[])

instance Inject NonEmptyF where
    inject :: forall (f :: k -> *). f ~> NonEmptyF f
inject = forall {k} (f :: k -> *) (a :: k). NonEmpty (f a) -> NonEmptyF f a
NonEmptyF forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> [a] -> NonEmpty a
:| [])

instance Inject MaybeF where
    inject :: forall (f :: k -> *). f ~> MaybeF f
inject = forall {k} (f :: k -> *) (a :: k). Maybe (f a) -> MaybeF f a
MaybeF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just

-- | Injects into a singleton map at 'mempty'.
instance Monoid k => Inject (NEMapF k) where
    inject :: forall (f :: k -> *). f ~> NEMapF k f
inject = forall {k} k1 (f :: k -> *) (a :: k).
NEMap k1 (f a) -> NEMapF k1 f a
NEMapF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. k -> a -> NEMap k a
NEM.singleton forall a. Monoid a => a
mempty

-- | Injects into a singleton map at 'mempty'.
instance Monoid k => Inject (MapF k) where
    inject :: forall (f :: k -> *). f ~> MapF k f
inject = forall {k} k1 (f :: k -> *) (a :: k). Map k1 (f a) -> MapF k1 f a
MapF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. k -> a -> Map k a
M.singleton forall a. Monoid a => a
mempty

-- | Injects with 0.
--
-- Equivalent to instance for @'EnvT' ('Data.Semigroup.Sum'
-- 'Numeric.Natural.Natural')@.
instance Inject Step where
    inject :: forall (f :: k -> *). f ~> Step f
inject = forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step Natural
0

-- | Injects into a singleton map at 0; same behavior as @'NEMapF'
-- ('Data.Semigroup.Sum' 'Numeric.Natural.Natural')@.
instance Inject Steps where
    inject :: forall (f :: k -> *). f ~> Steps f
inject = forall {k} (f :: k -> *) (a :: k). NEMap Natural (f a) -> Steps f a
Steps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. k -> a -> NEMap k a
NEM.singleton Natural
0

-- | Injects with 'False'.
--
-- Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift'
-- 'IdentityT'@.
instance Inject Flagged where
    inject :: forall (f :: k -> *). f ~> Flagged f
inject = forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged Bool
False

instance Inject (These1 f) where
    inject :: forall (f :: * -> *). f ~> These1 f f
inject = forall (f :: * -> *) (f :: * -> *). f ~> These1 f f
That1

instance Applicative f => Inject (Comp f :: (Type -> Type) -> Type -> Type) where
    inject :: forall (f :: * -> *). f ~> Comp f f
inject f x
x = forall (f :: * -> *) a. Applicative f => a -> f a
pure () forall {k} (f :: * -> *) (g :: k -> *) (a :: k) x.
f x -> (x -> g a) -> Comp f g a
:>>= forall a b. a -> b -> a
const f x
x

instance Applicative f => Inject ((:.:) f) where
    inject :: forall (f :: k -> *). f ~> (f :.: f)
inject f x
x = forall k2 k1 (f :: k2 -> *) (g :: k1 -> k2) (p :: k1).
f (g p) -> (:.:) f g p
Comp1 forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure f x
x

-- | Only uses 'zero'
instance Plus f => Inject ((:*:) f) where
    inject :: forall (f :: * -> *). f ~> (f :*: f)
inject = (forall (f :: * -> *) a. Plus f => f a
zero forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*:)

-- | Only uses 'zero'
instance Plus f => Inject (Product f) where
    inject :: forall (f :: * -> *). f ~> Product f f
inject = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair forall (f :: * -> *) a. Plus f => f a
zero

instance Inject ((:+:) f) where
    inject :: forall (f :: k -> *). f ~> (f :+: f)
inject = forall k (f :: k -> *) (f :: k -> *). f ~> (f :+: f)
R1

instance Inject (Sum f) where
    inject :: forall (f :: k -> *). f ~> Sum f f
inject = forall k (f :: k -> *) (f :: k -> *). f ~> Sum f f
InR

instance Inject (M1 i c) where
    inject :: forall (f :: k -> *). f ~> M1 i c f
inject = forall k i (c :: Meta) (f :: k -> *). f ~> M1 i c f
M1

instance Inject Alt.Alt where
    inject :: forall (f :: * -> *). f ~> Alt f
inject = forall (f :: * -> *). f ~> Alt f
Alt.liftAlt

instance Inject Free where
    inject :: forall (f :: * -> *). f ~> Free f
inject = forall (f :: * -> *). f ~> Free f
liftFree

instance Inject Free1 where
    inject :: forall (f :: * -> *). f ~> Free1 f
inject = forall (f :: * -> *). f ~> Free1 f
liftFree1

instance Inject FA.Ap where
    inject :: forall (f :: * -> *). f ~> Ap f
inject = forall (f :: * -> *). f ~> Ap f
FA.liftAp

instance Inject FAF.Ap where
    inject :: forall (f :: * -> *). f ~> Ap f
inject = forall (f :: * -> *). f ~> Ap f
FAF.liftAp

instance Inject IdentityT where
    inject :: forall (f :: k -> *). f ~> IdentityT f
inject = coerce :: forall a b. Coercible a b => a -> b
coerce

instance Inject Lift where
    inject :: forall (f :: * -> *). f ~> Lift f
inject = forall (f :: * -> *). f ~> Lift f
Other

instance Inject MaybeApply where
    inject :: forall (f :: * -> *). f ~> MaybeApply f
inject = forall (f :: * -> *) a. Either (f a) a -> MaybeApply f a
MaybeApply forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left

instance Inject Backwards where
    inject :: forall (f :: k -> *). f ~> Backwards f
inject = forall k (f :: k -> *). f ~> Backwards f
Backwards

instance Inject WrappedApplicative where
    inject :: forall (f :: * -> *). f ~> WrappedApplicative f
inject = forall (f :: * -> *). f ~> WrappedApplicative f
WrapApplicative

instance Inject (ReaderT r) where
    inject :: forall (f :: * -> *). f ~> ReaderT r f
inject = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const

instance Monoid e => Inject (EnvT e) where
    inject :: forall (f :: * -> *). f ~> EnvT e f
inject = forall e (w :: * -> *) a. e -> w a -> EnvT e w a
EnvT forall a. Monoid a => a
mempty

instance Inject Reverse where
    inject :: forall (f :: k -> *). f ~> Reverse f
inject = forall k (f :: k -> *). f ~> Reverse f
Reverse

instance Inject ProxyF where
    inject :: forall (f :: k -> *). f ~> ProxyF f
inject f x
_ = forall {k} {k} (f :: k) (a :: k). ProxyF f a
ProxyF

instance Monoid e => Inject (ConstF e) where
    inject :: forall (f :: k -> *). f ~> ConstF e f
inject f x
_ = forall {k} {k} e (f :: k) (a :: k). e -> ConstF e f a
ConstF forall a. Monoid a => a
mempty

instance (Inject s, Inject t) => Inject (ComposeT s t) where
    inject :: forall (f :: * -> *). f ~> ComposeT s t f
inject = forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
f (g m) a -> ComposeT f g m a
ComposeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject

instance HFunctor t => Inject (HLift t) where
    inject :: forall (f :: k -> *). f ~> HLift t f
inject = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure

-- | 'HFree' is the "free 'HBind' and 'Inject'" for any 'HFunctor'
instance HFunctor t => Inject (HFree t) where
    inject :: forall (f :: k -> *). f ~> HFree t f
inject = forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn

instance HBind Coyoneda where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> Coyoneda g) -> Coyoneda f ~> Coyoneda g
hbind f ~> Coyoneda g
f (Coyoneda b -> x
g f b
x) = b -> x
g forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f ~> Coyoneda g
f f b
x

instance HBind Ap where
    hbind :: forall (f :: * -> *) (g :: * -> *). (f ~> Ap g) -> Ap f ~> Ap g
hbind f ~> Ap g
f Ap f x
x = forall (g :: * -> *) (f :: * -> *) a.
Applicative g =>
(forall x. f x -> g x) -> Ap f a -> g a
runAp f ~> Ap g
f Ap f x
x

instance HBind ListF where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> ListF g) -> ListF f ~> ListF g
hbind f ~> ListF g
f = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap f ~> ListF g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). ListF f a -> [f a]
runListF

instance HBind NonEmptyF where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> NonEmptyF g) -> NonEmptyF f ~> NonEmptyF g
hbind f ~> NonEmptyF g
f = forall (t :: * -> *) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 f ~> NonEmptyF g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). NonEmptyF f a -> NonEmpty (f a)
runNonEmptyF

instance HBind MaybeF where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> MaybeF g) -> MaybeF f ~> MaybeF g
hbind f ~> MaybeF g
f = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap f ~> MaybeF g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). MaybeF f a -> Maybe (f a)
runMaybeF

-- | Equivalent to instance for @'EnvT' ('Data.Semigroup.Sum'
-- 'Numeric.Natural.Natural')@.
instance HBind Step where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> Step g) -> Step f ~> Step g
hbind f ~> Step g
f (Step Natural
n f x
x) = forall {k} (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
n forall a. Num a => a -> a -> a
+ Natural
m) g x
y
      where
        Step Natural
m g x
y = f ~> Step g
f f x
x

-- | Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift'
-- 'IdentityT'@.
instance HBind Flagged where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> Flagged g) -> Flagged f ~> Flagged g
hbind f ~> Flagged g
f (Flagged Bool
p f x
x) = forall {k} (f :: k -> *) (a :: k). Bool -> f a -> Flagged f a
Flagged (Bool
p Bool -> Bool -> Bool
|| Bool
q) g x
y
      where
        Flagged Bool
q g x
y = f ~> Flagged g
f f x
x

instance Alt f => HBind (These1 f) where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> These1 f g) -> These1 f f ~> These1 f g
hbind f ~> These1 f g
f = \case
      This1  f x
x   -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1 f x
x
      That1    f x
y -> f ~> These1 f g
f f x
y
      These1 f x
x f x
y -> case f ~> These1 f g
f f x
y of
        This1  f x
x'    -> forall (f :: * -> *) (g :: * -> *) a. f a -> These1 f g a
This1 (f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
x')
        That1     g x
y' -> forall (f :: * -> *) (f :: * -> *). f ~> These1 f f
That1 g x
y'
        These1 f x
x' g x
y' -> forall (f :: * -> *) (g :: * -> *) a. f a -> g a -> These1 f g a
These1 (f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
x') g x
y'

instance Plus f => HBind ((:*:) f) where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> (f :*: g)) -> (f :*: f) ~> (f :*: g)
hbind f ~> (f :*: g)
f (f x
x :*: f x
y) = (f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
x') forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
:*: g x
y'
      where
        f x
x' :*: g x
y' = f ~> (f :*: g)
f f x
y

instance Plus f => HBind (Product f) where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> Product f g) -> Product f f ~> Product f g
hbind f ~> Product f g
f (Pair f x
x f x
y) = forall {k} (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (f x
x forall (f :: * -> *) a. Alt f => f a -> f a -> f a
<!> f x
x') g x
y'
      where
        Pair f x
x' g x
y' = f ~> Product f g
f f x
y

instance HBind ((:+:) f) where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> (f :+: g)) -> (f :+: f) ~> (f :+: g)
hbind f ~> (f :+: g)
f = \case
      L1 f x
x -> forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 f x
x
      R1 f x
y -> f ~> (f :+: g)
f f x
y

instance HBind (Sum f) where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> Sum f g) -> Sum f f ~> Sum f g
hbind f ~> Sum f g
f = \case
      InL f x
x -> forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f x
x
      InR f x
y -> f ~> Sum f g
f f x
y

instance HBind (M1 i c) where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> M1 i c g) -> M1 i c f ~> M1 i c g
hbind f ~> M1 i c g
f (M1 f x
x) = f ~> M1 i c g
f f x
x

instance HBind Alt.Alt where
    hbind :: forall (f :: * -> *) (g :: * -> *). (f ~> Alt g) -> Alt f ~> Alt g
hbind f ~> Alt g
f Alt f x
x = forall (f :: * -> *) (g :: * -> *) a.
Alternative g =>
(forall x. f x -> g x) -> Alt f a -> g a
Alt.runAlt f ~> Alt g
f Alt f x
x

instance HBind Free where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> Free g) -> Free f ~> Free g
hbind f ~> Free g
f Free f x
x = forall (g :: * -> *) (f :: * -> *).
Monad g =>
(f ~> g) -> Free f ~> g
interpretFree f ~> Free g
f Free f x
x

instance HBind Free1 where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> Free1 g) -> Free1 f ~> Free1 g
hbind f ~> Free1 g
f Free1 f x
x = forall (g :: * -> *) (f :: * -> *).
Bind g =>
(f ~> g) -> Free1 f ~> g
interpretFree1 f ~> Free1 g
f Free1 f x
x

instance HBind FA.Ap where
    hbind :: forall (f :: * -> *) (g :: * -> *). (f ~> Ap g) -> Ap f ~> Ap g
hbind f ~> Ap g
f Ap f x
x = forall (g :: * -> *) (f :: * -> *) a.
Applicative g =>
(forall x. f x -> g x) -> Ap f a -> g a
FA.runAp f ~> Ap g
f Ap f x
x

instance HBind FAF.Ap where
    hbind :: forall (f :: * -> *) (g :: * -> *). (f ~> Ap g) -> Ap f ~> Ap g
hbind f ~> Ap g
f Ap f x
x = forall (g :: * -> *) (f :: * -> *) a.
Applicative g =>
(forall x. f x -> g x) -> Ap f a -> g a
FAF.runAp f ~> Ap g
f Ap f x
x

instance HBind IdentityT where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> IdentityT g) -> IdentityT f ~> IdentityT g
hbind f ~> IdentityT g
f = f ~> IdentityT g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT

instance HBind Lift where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> Lift g) -> Lift f ~> Lift g
hbind f ~> Lift g
f Lift f x
x = forall a r (f :: * -> *). (a -> r) -> (f a -> r) -> Lift f a -> r
elimLift forall (p :: * -> *) a. Pointed p => a -> p a
point f ~> Lift g
f Lift f x
x

instance HBind MaybeApply where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> MaybeApply g) -> MaybeApply f ~> MaybeApply g
hbind f ~> MaybeApply g
f = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either f ~> MaybeApply g
f forall (p :: * -> *) a. Pointed p => a -> p a
point forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. MaybeApply f a -> Either (f a) a
runMaybeApply

instance HBind Backwards where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> Backwards g) -> Backwards f ~> Backwards g
hbind f ~> Backwards g
f = f ~> Backwards g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Backwards f a -> f a
forwards

instance HBind WrappedApplicative where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> WrappedApplicative g)
-> WrappedApplicative f ~> WrappedApplicative g
hbind f ~> WrappedApplicative g
f = f ~> WrappedApplicative g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. WrappedApplicative f a -> f a
unwrapApplicative

instance HBind Reverse where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> Reverse g) -> Reverse f ~> Reverse g
hbind f ~> Reverse g
f = f ~> Reverse g
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (f :: k -> *) (a :: k). Reverse f a -> f a
getReverse

instance HBind ProxyF where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> ProxyF g) -> ProxyF f ~> ProxyF g
hbind f ~> ProxyF g
_ = coerce :: forall a b. Coercible a b => a -> b
coerce

-- | Combines the accumulators, Writer-style
instance Monoid e => HBind (EnvT e) where
    hbind :: forall (f :: * -> *) (g :: * -> *).
(f ~> EnvT e g) -> EnvT e f ~> EnvT e g
hbind f ~> EnvT e g
f (EnvT e
e f x
x) = forall e (w :: * -> *) a. e -> w a -> EnvT e w a
EnvT (e
e forall a. Semigroup a => a -> a -> a
<> e
e') g x
y
      where
        EnvT e
e' g x
y = f ~> EnvT e g
f f x
x

instance HBind t => HBind (HLift t) where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> HLift t g) -> HLift t f ~> HLift t g
hbind f ~> HLift t g
f = \case
      HPure   f x
x -> f ~> HLift t g
f f x
x
      HOther t f x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther forall a b. (a -> b) -> a -> b
$ (\f x
y -> case f ~> HLift t g
f f x
y of
        HPure  g x
z -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject g x
z
        HOther t g x
z -> t g x
z) forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
`hbind` t f x
x

-- | 'HFree' is the "free 'HBind'" for any 'HFunctor'
instance HFunctor t => HBind (HFree t) where
    hbind :: forall (f :: k -> *) (g :: k -> *).
(f ~> HFree t g) -> HFree t f ~> HFree t g
hbind f ~> HFree t g
f = \case
      HReturn f x
x -> f ~> HFree t g
f f x
x
      HJoin   t (HFree t f) x
x -> forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin forall a b. (a -> b) -> a -> b
$ forall {k} {k1} (t :: (k -> *) -> k1 -> *) (f :: k -> *)
       (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap (forall {k} (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind f ~> HFree t g
f) t (HFree t f) x
x