-- |
-- 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 :: (f <~> g) -> t f <~> t g
overHFunctor f :: f <~> g
f = (t f ~> t g) -> (t g ~> t f) -> t f <~> t g
forall k (f :: k -> *) (g :: k -> *).
(f ~> g) -> (g ~> f) -> f <~> g
isoF ((f ~> g) -> t f ~> t g
forall k k (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap ((f <~> g) -> f ~> g
forall k (f :: k -> *) (g :: k -> *). (f <~> g) -> f ~> g
viewF f <~> g
f)) ((g ~> f) -> t g ~> t f
forall k k (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HFunctor t =>
(f ~> g) -> t f ~> t g
hmap ((f <~> g) -> g ~> f
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
[ProxyF f a] -> ShowS
ProxyF f a -> String
(Int -> ProxyF f a -> ShowS)
-> (ProxyF f a -> String)
-> ([ProxyF f a] -> ShowS)
-> Show (ProxyF f a)
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)
Int -> ReadS (ProxyF f a)
ReadS [ProxyF f a]
(Int -> ReadS (ProxyF f a))
-> ReadS [ProxyF f a]
-> ReadPrec (ProxyF f a)
-> ReadPrec [ProxyF f a]
-> Read (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
(ProxyF f a -> ProxyF f a -> Bool)
-> (ProxyF f a -> ProxyF f a -> Bool) -> Eq (ProxyF f a)
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, Eq (ProxyF f a)
Eq (ProxyF f a) =>
(ProxyF f a -> ProxyF f a -> Ordering)
-> (ProxyF f a -> ProxyF f a -> Bool)
-> (ProxyF f a -> ProxyF f a -> Bool)
-> (ProxyF f a -> ProxyF f a -> Bool)
-> (ProxyF f a -> ProxyF f a -> Bool)
-> (ProxyF f a -> ProxyF f a -> ProxyF f a)
-> (ProxyF f a -> ProxyF f a -> ProxyF f a)
-> Ord (ProxyF f a)
ProxyF f a -> ProxyF f a -> Bool
ProxyF f a -> ProxyF f a -> Ordering
ProxyF f a -> ProxyF f a -> ProxyF f 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 (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
$cp1Ord :: forall k (f :: k) k (a :: k). Eq (ProxyF f a)
Ord, (a -> b) -> ProxyF f a -> ProxyF f b
(forall a b. (a -> b) -> ProxyF f a -> ProxyF f b)
-> (forall a b. a -> ProxyF f b -> ProxyF f a)
-> Functor (ProxyF f)
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 -> ProxyF f b -> ProxyF f a
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
<$ :: a -> ProxyF f b -> ProxyF f a
$c<$ :: forall k (f :: k) a b. a -> ProxyF f b -> ProxyF f a
fmap :: (a -> b) -> ProxyF f a -> ProxyF f b
$cfmap :: forall k (f :: k) a b. (a -> b) -> ProxyF f a -> ProxyF f b
Functor, (a -> m) -> ProxyF f a -> m
(forall m. Monoid m => ProxyF f m -> m)
-> (forall m a. Monoid m => (a -> m) -> ProxyF f a -> m)
-> (forall m a. Monoid m => (a -> m) -> ProxyF f a -> m)
-> (forall a b. (a -> b -> b) -> b -> ProxyF f a -> b)
-> (forall a b. (a -> b -> b) -> b -> ProxyF f a -> b)
-> (forall b a. (b -> a -> b) -> b -> ProxyF f a -> b)
-> (forall b a. (b -> a -> b) -> b -> ProxyF f a -> b)
-> (forall a. (a -> a -> a) -> ProxyF f a -> a)
-> (forall a. (a -> a -> a) -> ProxyF f a -> a)
-> (forall a. ProxyF f a -> [a])
-> (forall a. ProxyF f a -> Bool)
-> (forall a. ProxyF f a -> Int)
-> (forall a. Eq a => a -> ProxyF f a -> Bool)
-> (forall a. Ord a => ProxyF f a -> a)
-> (forall a. Ord a => ProxyF f a -> a)
-> (forall a. Num a => ProxyF f a -> a)
-> (forall a. Num a => ProxyF f a -> a)
-> Foldable (ProxyF f)
forall a. Eq a => a -> ProxyF f a -> Bool
forall a. Num a => ProxyF f a -> a
forall a. Ord a => ProxyF f a -> a
forall m. Monoid m => ProxyF f m -> m
forall a. ProxyF f a -> Bool
forall a. ProxyF f a -> Int
forall a. ProxyF f a -> [a]
forall a. (a -> a -> a) -> ProxyF f a -> a
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 b a. (b -> a -> b) -> b -> ProxyF f a -> b
forall a b. (a -> b -> b) -> b -> ProxyF 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 :: ProxyF f a -> a
$cproduct :: forall k (f :: k) a. Num a => ProxyF f a -> a
sum :: ProxyF f a -> a
$csum :: forall k (f :: k) a. Num a => ProxyF f a -> a
minimum :: ProxyF f a -> a
$cminimum :: forall k (f :: k) a. Ord a => ProxyF f a -> a
maximum :: ProxyF f a -> a
$cmaximum :: forall k (f :: k) a. Ord a => ProxyF f a -> a
elem :: a -> ProxyF f a -> Bool
$celem :: forall k (f :: k) a. Eq a => a -> ProxyF f a -> Bool
length :: ProxyF f a -> Int
$clength :: forall k (f :: k) a. ProxyF f a -> Int
null :: ProxyF f a -> Bool
$cnull :: forall k (f :: k) a. ProxyF f a -> Bool
toList :: ProxyF f a -> [a]
$ctoList :: forall k (f :: k) a. ProxyF f a -> [a]
foldl1 :: (a -> a -> a) -> ProxyF f a -> a
$cfoldl1 :: forall k (f :: k) a. (a -> a -> a) -> ProxyF f a -> a
foldr1 :: (a -> a -> a) -> ProxyF f a -> a
$cfoldr1 :: forall k (f :: k) a. (a -> a -> a) -> ProxyF f a -> a
foldl' :: (b -> a -> b) -> b -> ProxyF f a -> b
$cfoldl' :: forall k (f :: k) b a. (b -> a -> b) -> b -> ProxyF f a -> b
foldl :: (b -> a -> b) -> b -> ProxyF f a -> b
$cfoldl :: forall k (f :: k) b a. (b -> a -> b) -> b -> ProxyF f a -> b
foldr' :: (a -> b -> b) -> b -> ProxyF f a -> b
$cfoldr' :: forall k (f :: k) a b. (a -> b -> b) -> b -> ProxyF f a -> b
foldr :: (a -> b -> b) -> b -> ProxyF f a -> b
$cfoldr :: forall k (f :: k) a b. (a -> b -> b) -> b -> ProxyF f a -> b
foldMap' :: (a -> m) -> ProxyF f a -> m
$cfoldMap' :: forall k (f :: k) m a. Monoid m => (a -> m) -> ProxyF f a -> m
foldMap :: (a -> m) -> ProxyF f a -> m
$cfoldMap :: forall k (f :: k) m a. Monoid m => (a -> m) -> ProxyF f a -> m
fold :: ProxyF f m -> m
$cfold :: forall k (f :: k) m. Monoid m => ProxyF f m -> m
Foldable, Functor (ProxyF f)
Foldable (ProxyF f)
(Functor (ProxyF f), Foldable (ProxyF f)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> ProxyF f a -> f (ProxyF f b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ProxyF f (f a) -> f (ProxyF f a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ProxyF f a -> m (ProxyF f b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ProxyF f (m a) -> m (ProxyF f a))
-> Traversable (ProxyF f)
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
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 (m :: * -> *) a. Monad m => ProxyF f (m a) -> m (ProxyF f a)
forall (f :: * -> *) a.
Applicative f =>
ProxyF f (f a) -> f (ProxyF f a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ProxyF f a -> m (ProxyF f b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ProxyF f a -> f (ProxyF f b)
sequence :: 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 :: (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 :: 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 :: (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)
$cp2Traversable :: forall k (f :: k). Foldable (ProxyF f)
$cp1Traversable :: forall k (f :: k). Functor (ProxyF f)
Traversable, Typeable, (forall x. ProxyF f a -> Rep (ProxyF f a) x)
-> (forall x. Rep (ProxyF f a) x -> ProxyF f a)
-> Generic (ProxyF f a)
forall x. Rep (ProxyF f a) x -> ProxyF f a
forall x. ProxyF f a -> Rep (ProxyF f a) x
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, Typeable (ProxyF f a)
DataType
Constr
Typeable (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))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ProxyF f a))
-> (ProxyF f a -> Constr)
-> (ProxyF f a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ProxyF f a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ProxyF f a)))
-> ((forall b. Data b => b -> b) -> ProxyF f a -> ProxyF f a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r)
-> (forall u. (forall d. Data d => d -> u) -> ProxyF f a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ProxyF f a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a))
-> Data (ProxyF f a)
ProxyF f a -> DataType
ProxyF f a -> Constr
(forall b. Data b => b -> b) -> ProxyF f a -> ProxyF f a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ProxyF f a -> c (ProxyF f a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ProxyF f 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) -> ProxyF f a -> u
forall u. (forall d. Data d => d -> u) -> ProxyF f a -> [u]
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 r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ProxyF f a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (ProxyF f a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ProxyF f a -> m (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)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ProxyF f a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ProxyF f a))
$cProxyF :: Constr
$tProxyF :: DataType
gmapMo :: (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 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 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 :: 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 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 :: (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 :: (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 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 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 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 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)
$cp1Data :: forall k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k) =>
Typeable (ProxyF f a)
Data)

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

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

instance HFunctor ProxyF where
    hmap :: (f ~> g) -> ProxyF f ~> ProxyF g
hmap _ = ProxyF f x -> ProxyF g x
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 { ConstF e f a -> e
getConstF :: e }
  deriving (Int -> ConstF e f a -> ShowS
[ConstF e f a] -> ShowS
ConstF e f a -> String
(Int -> ConstF e f a -> ShowS)
-> (ConstF e f a -> String)
-> ([ConstF e f a] -> ShowS)
-> Show (ConstF e f a)
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)
Int -> ReadS (ConstF e f a)
ReadS [ConstF e f a]
(Int -> ReadS (ConstF e f a))
-> ReadS [ConstF e f a]
-> ReadPrec (ConstF e f a)
-> ReadPrec [ConstF e f a]
-> Read (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
(ConstF e f a -> ConstF e f a -> Bool)
-> (ConstF e f a -> ConstF e f a -> Bool) -> Eq (ConstF e f a)
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, Eq (ConstF e f a)
Eq (ConstF e f a) =>
(ConstF e f a -> ConstF e f a -> Ordering)
-> (ConstF e f a -> ConstF e f a -> Bool)
-> (ConstF e f a -> ConstF e f a -> Bool)
-> (ConstF e f a -> ConstF e f a -> Bool)
-> (ConstF e f a -> ConstF e f a -> Bool)
-> (ConstF e f a -> ConstF e f a -> ConstF e f a)
-> (ConstF e f a -> ConstF e f a -> ConstF e f a)
-> Ord (ConstF e f a)
ConstF e f a -> ConstF e f a -> Bool
ConstF e f a -> ConstF e f a -> Ordering
ConstF e f a -> ConstF e f a -> ConstF e f 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 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
$cp1Ord :: forall e k (f :: k) k (a :: k). Ord e => Eq (ConstF e f a)
Ord, (a -> b) -> ConstF e f a -> ConstF e f b
(forall a b. (a -> b) -> ConstF e f a -> ConstF e f b)
-> (forall a b. a -> ConstF e f b -> ConstF e f a)
-> Functor (ConstF e f)
forall a b. a -> ConstF e f b -> ConstF e f a
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
<$ :: 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 :: (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, (a -> m) -> ConstF e f a -> m
(forall m. Monoid m => ConstF e f m -> m)
-> (forall m a. Monoid m => (a -> m) -> ConstF e f a -> m)
-> (forall m a. Monoid m => (a -> m) -> ConstF e f a -> m)
-> (forall a b. (a -> b -> b) -> b -> ConstF e f a -> b)
-> (forall a b. (a -> b -> b) -> b -> ConstF e f a -> b)
-> (forall b a. (b -> a -> b) -> b -> ConstF e f a -> b)
-> (forall b a. (b -> a -> b) -> b -> ConstF e f a -> b)
-> (forall a. (a -> a -> a) -> ConstF e f a -> a)
-> (forall a. (a -> a -> a) -> ConstF e f a -> a)
-> (forall a. ConstF e f a -> [a])
-> (forall a. ConstF e f a -> Bool)
-> (forall a. ConstF e f a -> Int)
-> (forall a. Eq a => a -> ConstF e f a -> Bool)
-> (forall a. Ord a => ConstF e f a -> a)
-> (forall a. Ord a => ConstF e f a -> a)
-> (forall a. Num a => ConstF e f a -> a)
-> (forall a. Num a => ConstF e f a -> a)
-> Foldable (ConstF e f)
forall a. Eq a => a -> ConstF e f a -> Bool
forall a. Num a => ConstF e f a -> a
forall a. Ord a => ConstF e f a -> a
forall m. Monoid m => ConstF e f m -> m
forall a. ConstF e f a -> Bool
forall a. ConstF e f a -> Int
forall a. ConstF e f a -> [a]
forall a. (a -> a -> a) -> ConstF e f a -> a
forall m a. Monoid m => (a -> m) -> ConstF e f a -> m
forall b a. (b -> a -> b) -> b -> ConstF e f a -> b
forall a b. (a -> b -> b) -> b -> ConstF e f a -> b
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 :: ConstF e f a -> a
$cproduct :: forall e k (f :: k) a. Num a => ConstF e f a -> a
sum :: ConstF e f a -> a
$csum :: forall e k (f :: k) a. Num a => ConstF e f a -> a
minimum :: ConstF e f a -> a
$cminimum :: forall e k (f :: k) a. Ord a => ConstF e f a -> a
maximum :: ConstF e f a -> a
$cmaximum :: forall e k (f :: k) a. Ord a => ConstF e f a -> a
elem :: a -> ConstF e f a -> Bool
$celem :: forall e k (f :: k) a. Eq a => a -> ConstF e f a -> Bool
length :: ConstF e f a -> Int
$clength :: forall e k (f :: k) a. ConstF e f a -> Int
null :: ConstF e f a -> Bool
$cnull :: forall e k (f :: k) a. ConstF e f a -> Bool
toList :: ConstF e f a -> [a]
$ctoList :: forall e k (f :: k) a. ConstF e f a -> [a]
foldl1 :: (a -> a -> a) -> ConstF e f a -> a
$cfoldl1 :: forall e k (f :: k) a. (a -> a -> a) -> ConstF e f a -> a
foldr1 :: (a -> a -> a) -> ConstF e f a -> a
$cfoldr1 :: forall e k (f :: k) a. (a -> a -> a) -> ConstF e f a -> a
foldl' :: (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 :: (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' :: (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 :: (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' :: (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 :: (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 :: ConstF e f m -> m
$cfold :: forall e k (f :: k) m. Monoid m => ConstF e f m -> m
Foldable, Functor (ConstF e f)
Foldable (ConstF e f)
(Functor (ConstF e f), Foldable (ConstF e f)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> ConstF e f a -> f (ConstF e f b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    ConstF e f (f a) -> f (ConstF e f a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> ConstF e f a -> m (ConstF e f b))
-> (forall (m :: * -> *) a.
    Monad m =>
    ConstF e f (m a) -> m (ConstF e f a))
-> Traversable (ConstF e f)
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
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 (m :: * -> *) a.
Monad m =>
ConstF e f (m a) -> m (ConstF e f a)
forall (f :: * -> *) a.
Applicative f =>
ConstF e f (f a) -> f (ConstF e f a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConstF e f a -> m (ConstF e f b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ConstF e f a -> f (ConstF e f b)
sequence :: 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 :: (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 :: 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 :: (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)
$cp2Traversable :: forall e k (f :: k). Foldable (ConstF e f)
$cp1Traversable :: forall e k (f :: k). Functor (ConstF e f)
Traversable, Typeable, (forall x. ConstF e f a -> Rep (ConstF e f a) x)
-> (forall x. Rep (ConstF e f a) x -> ConstF e f a)
-> Generic (ConstF e f a)
forall x. Rep (ConstF e f a) x -> ConstF e f a
forall x. ConstF e f a -> Rep (ConstF e f a) x
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, Typeable (ConstF e f a)
DataType
Constr
Typeable (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))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ConstF e f a))
-> (ConstF e f a -> Constr)
-> (ConstF e f a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ConstF e f a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ConstF e f a)))
-> ((forall b. Data b => b -> b) -> ConstF e f a -> ConstF e f a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConstF e f a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ConstF e f a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a))
-> Data (ConstF e f a)
ConstF e f a -> DataType
ConstF e f a -> Constr
(forall b. Data b => b -> b) -> ConstF e f a -> ConstF e f a
(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 b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConstF e f 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) -> ConstF e f a -> u
forall u. (forall d. Data d => d -> u) -> ConstF e f a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConstF e f a -> r
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 (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (ConstF e f a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConstF e f a -> m (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)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ConstF e f a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConstF e f a))
$cConstF :: Constr
$tConstF :: DataType
gmapMo :: (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 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 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 :: 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 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 :: (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 :: (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 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 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 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 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)
$cp1Data :: forall e k (f :: k) k (a :: k).
(Typeable f, Typeable a, Typeable k, Typeable k, Data e) =>
Typeable (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 :: (a -> b) -> ConstF e f b -> ConstF e f a
contramap _ = ConstF e f b -> ConstF e f a
forall a b. Coercible a b => a -> b
coerce
-- | @since 0.3.0.0
instance Monoid e => Divisible (ConstF e f) where
    divide :: (a -> (b, c)) -> ConstF e f b -> ConstF e f c -> ConstF e f a
divide _ (ConstF x :: e
x) (ConstF y :: e
y) = e -> ConstF e f a
forall k k e (f :: k) (a :: k). e -> ConstF e f a
ConstF (e
x e -> e -> e
forall a. Semigroup a => a -> a -> a
<> e
y)
    conquer :: ConstF e f a
conquer = e -> ConstF e f a
forall k k e (f :: k) (a :: k). e -> ConstF e f a
ConstF e
forall a. Monoid a => a
mempty
-- | @since 0.3.0.0
instance Semigroup e => Divise (ConstF e f) where
    divise :: (a -> (b, c)) -> ConstF e f b -> ConstF e f c -> ConstF e f a
divise _ (ConstF x :: e
x) (ConstF y :: e
y) = e -> ConstF e f a
forall k k e (f :: k) (a :: k). e -> ConstF e f a
ConstF (e
x e -> e -> e
forall a. Semigroup a => a -> a -> a
<> e
y)
-- | @since 0.3.0.0
instance Invariant (ConstF e f) where
    invmap :: (a -> b) -> (b -> a) -> ConstF e f a -> ConstF e f b
invmap _ _ = ConstF e f a -> ConstF e f b
forall a b. Coercible a b => a -> b
coerce

instance HFunctor (ConstF e) where
    hmap :: (f ~> g) -> ConstF e f ~> ConstF e g
hmap _ = ConstF e f x -> ConstF e g x
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 a -> HLift t f b -> HLift t f a
(a -> b) -> HLift t f a -> HLift t f b
(forall a b. (a -> b) -> HLift t f a -> HLift t f b)
-> (forall a b. a -> HLift t f b -> HLift t f a)
-> Functor (HLift t f)
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
<$ :: 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 :: (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 :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> HLift t f a -> ShowS
liftShowsPrec sp :: Int -> a -> ShowS
sp sl :: [a] -> ShowS
sl d :: Int
d = \case
      HPure x :: f a
x -> (Int -> f a -> ShowS) -> String -> Int -> f a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) "HPure" Int
d f a
x
      HOther x :: t f a
x -> (Int -> t f a -> ShowS) -> String -> Int -> t f a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> t f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) "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 :: (a -> b -> Bool) -> HLift t f a -> HLift t f b -> Bool
liftEq eq :: a -> b -> Bool
eq = \case
      HPure  x :: f a
x -> \case
        HPure  y :: f b
y -> (a -> b -> Bool) -> f a -> f b -> Bool
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 _ -> Bool
False
      HOther x :: t f a
x -> \case
        HPure  _ -> Bool
False
        HOther y :: t f b
y -> (a -> b -> Bool) -> t f a -> t f b -> Bool
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 :: (a -> b -> Ordering) -> HLift t f a -> HLift t f b -> Ordering
liftCompare c :: a -> b -> Ordering
c = \case
      HPure  x :: f a
x -> \case
        HPure  y :: f b
y -> (a -> b -> Ordering) -> f a -> f b -> Ordering
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 _ -> Ordering
LT
      HOther x :: t f a
x -> \case
        HPure  _ -> Ordering
GT
        HOther y :: t f b
y -> (a -> b -> Ordering) -> t f a -> t f b -> Ordering
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 :: (f ~> g) -> HLift t f ~> HLift t g
hmap f :: f ~> g
f = \case
      HPure  x :: f x
x -> g x -> HLift t g x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  (f x -> g x
f ~> g
f f x
x)
      HOther x :: t f x
x -> t g x -> HLift t g x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther ((f ~> g) -> t f x -> t g x
forall k k (t :: (k -> *) -> k -> *) (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 :: (a -> b) -> HLift t f b -> HLift t f a
contramap f :: a -> b
f = \case
      HPure  x :: f b
x  -> f a -> HLift t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  ((a -> b) -> f b -> f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f f b
x)
      HOther xs :: t f b
xs -> t f a -> HLift t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther ((a -> b) -> t f b -> t f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f t f b
xs)

-- | @since 0.3.0.0
instance (Invariant f, Invariant (t f)) => Invariant (HLift t f) where
    invmap :: (a -> b) -> (b -> a) -> HLift t f a -> HLift t f b
invmap f :: a -> b
f g :: b -> a
g = \case
      HPure  x :: f a
x  -> f b -> HLift t f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HLift t f a
HPure  ((a -> b) -> (b -> a) -> f a -> f b
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 xs :: t f a
xs -> t f b -> HLift t f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t f a -> HLift t f a
HOther ((a -> b) -> (b -> a) -> t f a -> t f b
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 :: HLift t f a -> t f a
retractHLift = \case
    HPure  x :: f a
x -> f a -> t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f a
x
    HOther x :: 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 :: (a -> b) -> HFree t f b -> HFree t f a
contramap f :: a -> b
f = \case
      HReturn x :: f b
x  -> f a -> HFree t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn ((a -> b) -> f b -> f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f f b
x)
      HJoin   xs :: t (HFree t f) b
xs -> t (HFree t f) a -> HFree t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin   ((a -> b) -> t (HFree t f) b -> t (HFree t f) a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> f a
contramap a -> b
f t (HFree t f) b
xs)

instance (Invariant f, Invariant (t (HFree t f))) => Invariant (HFree t f) where
    invmap :: (a -> b) -> (b -> a) -> HFree t f a -> HFree t f b
invmap f :: a -> b
f g :: b -> a
g = \case
      HReturn x :: f a
x  -> f b -> HFree t f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn ((a -> b) -> (b -> a) -> f a -> f b
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   xs :: t (HFree t f) a
xs -> t (HFree t f) b -> HFree t f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin   ((a -> b) -> (b -> a) -> t (HFree t f) a -> t (HFree t f) b
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 :: (f ~> g) -> (t g ~> g) -> HFree t f ~> g
foldHFree f :: f ~> g
f g :: t g ~> g
g = HFree t f x -> g x
HFree t f ~> g
go
  where
    go :: HFree t f ~> g
    go :: HFree t f x -> g x
go (HReturn x :: f x
x) = f x -> g x
f ~> g
f f x
x
    go (HJoin   x :: t (HFree t f) x
x) = t g x -> g x
t g ~> g
g ((HFree t f ~> g) -> t (HFree t f) x -> t g x
forall k k (t :: (k -> *) -> k -> *) (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 :: HFree t f a -> t f a
retractHFree = \case
    HReturn x :: f a
x -> f a -> t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject f a
x
    HJoin   x :: t (HFree t f) a
x -> (HFree t f ~> t f) -> t (HFree t f) a -> t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind HFree t f ~> t f
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 :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> HFree t f a -> ShowS
liftShowsPrec sp :: Int -> a -> ShowS
sp sl :: [a] -> ShowS
sl d :: Int
d = \case
      HReturn x :: f a
x -> (Int -> f a -> ShowS) -> String -> Int -> f a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) "HReturn" Int
d f a
x
      HJoin   x :: t (HFree t f) a
x -> (Int -> t (HFree t f) a -> ShowS)
-> String -> Int -> t (HFree t f) a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> t (HFree t f) a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl) "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 = (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> HFree t f a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
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 :: (f ~> g) -> HFree t f ~> HFree t g
hmap f :: f ~> g
f = HFree t f x -> HFree t g x
HFree t f ~> HFree t g
go
      where
        go :: HFree t f ~> HFree t g
        go :: HFree t f x -> HFree t g x
go = \case
          HReturn x :: f x
x -> g x -> HFree t g x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn (f x -> g x
f ~> g
f f x
x)
          HJoin   x :: t (HFree t f) x
x -> t (HFree t g) x -> HFree t g x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
t (HFree t f) a -> HFree t f a
HJoin ((HFree t f ~> HFree t g) -> t (HFree t f) x -> t (HFree t g) x
forall k k (t :: (k -> *) -> k -> *) (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 :: (a -> b) -> f a -> t f b
injectMap f :: a -> b
f = f b -> t f b
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject (f b -> t f b) -> (f a -> f b) -> f a -> t f b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> f a -> f b
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 :: (a -> b) -> f b -> t f a
injectContramap f :: a -> b
f = f a -> t f a
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
Inject t =>
f ~> t f
inject (f a -> t f a) -> (f b -> f a) -> f b -> t f a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> f b -> f a
forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b -> 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 :: f ~> t g
f = t (t g) x -> t g x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *).
HBind t =>
t (t f) ~> t f
hjoin (t (t g) x -> t g x) -> (t f x -> t (t g) x) -> t f x -> t g x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f ~> t g) -> t f ~> t (t g)
forall k k (t :: (k -> *) -> k -> *) (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 = (t f ~> t f) -> t (t f) ~> t f
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (g :: k -> *).
HBind t =>
(f ~> t g) -> t f ~> t g
hbind t f ~> t f
forall a. a -> a
id
    {-# MINIMAL hbind | hjoin #-}

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

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

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

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

instance Inject NonEmptyF where
    inject :: f x -> NonEmptyF f x
inject = 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)
-> (f x -> NonEmpty (f x)) -> f x -> NonEmptyF f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f x -> [f x] -> NonEmpty (f x)
forall a. a -> [a] -> NonEmpty a
:| [])

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

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

-- | Injects into a singleton map at 'mempty'.
instance Monoid k => Inject (MapF k) where
    inject :: f x -> MapF k f x
inject = Map k (f x) -> MapF k f x
forall k k (f :: k -> *) (a :: k). Map k (f a) -> MapF k f a
MapF (Map k (f x) -> MapF k f x)
-> (f x -> Map k (f x)) -> f x -> MapF k f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> f x -> Map k (f x)
forall k a. k -> a -> Map k a
M.singleton k
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 :: f x -> Step f x
inject = Natural -> f x -> Step f x
forall k (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step 0

-- | Injects into a singleton map at 0; same behavior as @'NEMapF'
-- ('Data.Semigroup.Sum' 'Numeric.Natural.Natural')@.
instance Inject Steps where
    inject :: f x -> Steps f x
inject = 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) -> Steps f x)
-> (f x -> NEMap Natural (f x)) -> f x -> Steps f x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> f x -> NEMap Natural (f x)
forall k a. k -> a -> NEMap k a
NEM.singleton 0

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

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

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

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

-- | Only uses 'zero'
instance Plus f => Inject ((:*:) f) where
    inject :: f x -> (:*:) f f x
inject = (f x
forall (f :: * -> *) a. Plus f => f a
zero f x -> f x -> (:*:) f f x
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 :: f x -> Product f f x
inject = f x -> f x -> Product f f x
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair f x
forall (f :: * -> *) a. Plus f => f a
zero

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

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

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

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

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

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

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

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

instance Inject IdentityT where
    inject :: f x -> IdentityT f x
inject = f x -> IdentityT f x
forall a b. Coercible a b => a -> b
coerce

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

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

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

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

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

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

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

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

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

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

instance HFunctor t => Inject (HLift t) where
    inject :: f x -> HLift t f x
inject = f x -> HLift t f x
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 :: f x -> HFree t f x
inject = f x -> HFree t f x
forall k (t :: (k -> *) -> k -> *) (f :: k -> *) (a :: k).
f a -> HFree t f a
HReturn

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

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

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

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

instance HBind MaybeF where
    hbind :: (f ~> MaybeF g) -> MaybeF f ~> MaybeF g
hbind f :: f ~> MaybeF g
f = (f x -> MaybeF g x) -> Maybe (f x) -> MaybeF g x
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap f x -> MaybeF g x
f ~> MaybeF g
f (Maybe (f x) -> MaybeF g x)
-> (MaybeF f x -> Maybe (f x)) -> MaybeF f x -> MaybeF g x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MaybeF f x -> Maybe (f x)
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 :: (f ~> Step g) -> Step f ~> Step g
hbind f :: f ~> Step g
f (Step n :: Natural
n x :: f x
x) = Natural -> g x -> Step g x
forall k (f :: k -> *) (a :: k). Natural -> f a -> Step f a
Step (Natural
n Natural -> Natural -> Natural
forall a. Num a => a -> a -> a
+ Natural
m) g x
y
      where
        Step m :: Natural
m y :: g x
y = f x -> Step g x
f ~> Step g
f f x
x

-- | Equivalent to instance for @'EnvT' 'Data.Semigroup.Any'@ and @'HLift'
-- 'IdentityT'@.
instance HBind Flagged where
    hbind :: (f ~> Flagged g) -> Flagged f ~> Flagged g
hbind f :: f ~> Flagged g
f (Flagged p :: Bool
p x :: f x
x) = Bool -> g x -> Flagged g 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 q :: Bool
q y :: g x
y = f x -> Flagged g x
f ~> Flagged g
f f x
x

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

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

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

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

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

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

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

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

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

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

instance HBind IdentityT where
    hbind :: (f ~> IdentityT g) -> IdentityT f ~> IdentityT g
hbind f :: f ~> IdentityT g
f = f x -> IdentityT g x
f ~> IdentityT g
f (f x -> IdentityT g x)
-> (IdentityT f x -> f x) -> IdentityT f x -> IdentityT g 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

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

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

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

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

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

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

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

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

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