{-# LANGUAGE PolyKinds, DeriveGeneric #-}
-- | Basic functors.
--
-- Definitions of the type-level equivalents of
-- 'const', 'id', and ('.'), and a definition of
-- the lifted function space.
--
-- These datatypes are generally useful, but in this
-- library, they're primarily used as parameters for
-- the 'NP', 'NS', 'POP', and 'SOP' types.
--
-- We define own variants of 'Control.Applicative.Const',
-- 'Data.Functor.Identity.Identity' and 'Data.Functor.Compose.Compose' for
-- various reasons.
--
-- * 'Control.Applicative.Const' and 'Data.Functor.Compose.Compose' become
-- kind polymorphic only in @base-4.9.0.0@ (@transformers-0.5.0.0@).
--
-- * Shorter names are convenient, and pattern synonyms aren't
-- (yet) powerful enough, particularly exhaustiveness check doesn't work
-- properly. See <https://ghc.haskell.org/trac/ghc/ticket/8779>.
--
module Data.SOP.BasicFunctors
  ( -- * Basic functors
    K(..)
  , unK
  , I(..)
  , unI
  , (:.:)(..)
  , unComp
    -- * Mapping functions
  , mapII
  , mapIK
  , mapKI
  , mapKK
  , mapIII
  , mapIIK
  , mapIKI
  , mapIKK
  , mapKII
  , mapKIK
  , mapKKI
  , mapKKK
  ) where

import Data.Semigroup (Semigroup (..))
import Data.Kind (Type)
import qualified GHC.Generics as GHC

import Data.Functor.Classes

import Control.DeepSeq (NFData(..))
#if MIN_VERSION_deepseq(1,4,3)
import Control.DeepSeq (NFData1(..), NFData2(..))
#endif

-- * Basic functors

-- | The constant type functor.
--
-- Like 'Data.Functor.Constant.Constant', but kind-polymorphic
-- in its second argument and with a shorter name.
--
newtype K (a :: Type) (b :: k) = K a
  deriving ((a -> b) -> K a a -> K a b
(forall a b. (a -> b) -> K a a -> K a b)
-> (forall a b. a -> K a b -> K a a) -> Functor (K a)
forall a b. a -> K a b -> K a a
forall a b. (a -> b) -> K a a -> K a b
forall a a b. a -> K a b -> K a a
forall a a b. (a -> b) -> K a a -> K a b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> K a b -> K a a
$c<$ :: forall a a b. a -> K a b -> K a a
fmap :: (a -> b) -> K a a -> K a b
$cfmap :: forall a a b. (a -> b) -> K a a -> K a b
Functor, (a -> m) -> K a a -> m
(forall m. Monoid m => K a m -> m)
-> (forall m a. Monoid m => (a -> m) -> K a a -> m)
-> (forall m a. Monoid m => (a -> m) -> K a a -> m)
-> (forall a b. (a -> b -> b) -> b -> K a a -> b)
-> (forall a b. (a -> b -> b) -> b -> K a a -> b)
-> (forall b a. (b -> a -> b) -> b -> K a a -> b)
-> (forall b a. (b -> a -> b) -> b -> K a a -> b)
-> (forall a. (a -> a -> a) -> K a a -> a)
-> (forall a. (a -> a -> a) -> K a a -> a)
-> (forall a. K a a -> [a])
-> (forall a. K a a -> Bool)
-> (forall a. K a a -> Int)
-> (forall a. Eq a => a -> K a a -> Bool)
-> (forall a. Ord a => K a a -> a)
-> (forall a. Ord a => K a a -> a)
-> (forall a. Num a => K a a -> a)
-> (forall a. Num a => K a a -> a)
-> Foldable (K a)
forall a. Eq a => a -> K a a -> Bool
forall a. Num a => K a a -> a
forall a. Ord a => K a a -> a
forall m. Monoid m => K a m -> m
forall a. K a a -> Bool
forall a. K a a -> Int
forall a. K a a -> [a]
forall a. (a -> a -> a) -> K a a -> a
forall a a. Eq a => a -> K a a -> Bool
forall a a. Num a => K a a -> a
forall a a. Ord a => K a a -> a
forall m a. Monoid m => (a -> m) -> K a a -> m
forall a m. Monoid m => K a m -> m
forall a a. K a a -> Bool
forall a a. K a a -> Int
forall a a. K a a -> [a]
forall b a. (b -> a -> b) -> b -> K a a -> b
forall a b. (a -> b -> b) -> b -> K a a -> b
forall a a. (a -> a -> a) -> K a a -> a
forall a m a. Monoid m => (a -> m) -> K a a -> m
forall a b a. (b -> a -> b) -> b -> K a a -> b
forall a a b. (a -> b -> b) -> b -> K a 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 :: K a a -> a
$cproduct :: forall a a. Num a => K a a -> a
sum :: K a a -> a
$csum :: forall a a. Num a => K a a -> a
minimum :: K a a -> a
$cminimum :: forall a a. Ord a => K a a -> a
maximum :: K a a -> a
$cmaximum :: forall a a. Ord a => K a a -> a
elem :: a -> K a a -> Bool
$celem :: forall a a. Eq a => a -> K a a -> Bool
length :: K a a -> Int
$clength :: forall a a. K a a -> Int
null :: K a a -> Bool
$cnull :: forall a a. K a a -> Bool
toList :: K a a -> [a]
$ctoList :: forall a a. K a a -> [a]
foldl1 :: (a -> a -> a) -> K a a -> a
$cfoldl1 :: forall a a. (a -> a -> a) -> K a a -> a
foldr1 :: (a -> a -> a) -> K a a -> a
$cfoldr1 :: forall a a. (a -> a -> a) -> K a a -> a
foldl' :: (b -> a -> b) -> b -> K a a -> b
$cfoldl' :: forall a b a. (b -> a -> b) -> b -> K a a -> b
foldl :: (b -> a -> b) -> b -> K a a -> b
$cfoldl :: forall a b a. (b -> a -> b) -> b -> K a a -> b
foldr' :: (a -> b -> b) -> b -> K a a -> b
$cfoldr' :: forall a a b. (a -> b -> b) -> b -> K a a -> b
foldr :: (a -> b -> b) -> b -> K a a -> b
$cfoldr :: forall a a b. (a -> b -> b) -> b -> K a a -> b
foldMap' :: (a -> m) -> K a a -> m
$cfoldMap' :: forall a m a. Monoid m => (a -> m) -> K a a -> m
foldMap :: (a -> m) -> K a a -> m
$cfoldMap :: forall a m a. Monoid m => (a -> m) -> K a a -> m
fold :: K a m -> m
$cfold :: forall a m. Monoid m => K a m -> m
Foldable, Functor (K a)
Foldable (K a)
(Functor (K a), Foldable (K a)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> K a a -> f (K a b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    K a (f a) -> f (K a a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> K a a -> m (K a b))
-> (forall (m :: * -> *) a. Monad m => K a (m a) -> m (K a a))
-> Traversable (K a)
(a -> f b) -> K a a -> f (K a b)
forall a. Functor (K a)
forall a. Foldable (K a)
forall a (m :: * -> *) a. Monad m => K a (m a) -> m (K a a)
forall a (f :: * -> *) a. Applicative f => K a (f a) -> f (K a a)
forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> K a a -> m (K a b)
forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> K a a -> f (K a 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 => K a (m a) -> m (K a a)
forall (f :: * -> *) a. Applicative f => K a (f a) -> f (K a a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> K a a -> m (K a b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> K a a -> f (K a b)
sequence :: K a (m a) -> m (K a a)
$csequence :: forall a (m :: * -> *) a. Monad m => K a (m a) -> m (K a a)
mapM :: (a -> m b) -> K a a -> m (K a b)
$cmapM :: forall a (m :: * -> *) a b.
Monad m =>
(a -> m b) -> K a a -> m (K a b)
sequenceA :: K a (f a) -> f (K a a)
$csequenceA :: forall a (f :: * -> *) a. Applicative f => K a (f a) -> f (K a a)
traverse :: (a -> f b) -> K a a -> f (K a b)
$ctraverse :: forall a (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> K a a -> f (K a b)
$cp2Traversable :: forall a. Foldable (K a)
$cp1Traversable :: forall a. Functor (K a)
Traversable, (forall x. K a b -> Rep (K a b) x)
-> (forall x. Rep (K a b) x -> K a b) -> Generic (K a b)
forall x. Rep (K a b) x -> K a b
forall x. K a b -> Rep (K a b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a k (b :: k) x. Rep (K a b) x -> K a b
forall a k (b :: k) x. K a b -> Rep (K a b) x
$cto :: forall a k (b :: k) x. Rep (K a b) x -> K a b
$cfrom :: forall a k (b :: k) x. K a b -> Rep (K a b) x
GHC.Generic)

-- | @since 0.2.4.0
instance Eq2 K where
    liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> K a c -> K b d -> Bool
liftEq2 eq :: a -> b -> Bool
eq _ (K x :: a
x) (K y :: b
y) = a -> b -> Bool
eq a
x b
y
-- | @since 0.2.4.0
instance Ord2 K where
    liftCompare2 :: (a -> b -> Ordering)
-> (c -> d -> Ordering) -> K a c -> K b d -> Ordering
liftCompare2 comp :: a -> b -> Ordering
comp _ (K x :: a
x) (K y :: b
y) = a -> b -> Ordering
comp a
x b
y
-- | @since 0.2.4.0
instance Read2 K where
    liftReadsPrec2 :: (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (K a b)
liftReadsPrec2 rp :: Int -> ReadS a
rp _ _ _ = (String -> ReadS (K a b)) -> Int -> ReadS (K a b)
forall a. (String -> ReadS a) -> Int -> ReadS a
readsData ((String -> ReadS (K a b)) -> Int -> ReadS (K a b))
-> (String -> ReadS (K a b)) -> Int -> ReadS (K a b)
forall a b. (a -> b) -> a -> b
$
         (Int -> ReadS a)
-> String -> (a -> K a b) -> String -> ReadS (K a b)
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith Int -> ReadS a
rp "K" a -> K a b
forall k a (b :: k). a -> K a b
K
-- | @since 0.2.4.0
instance Show2 K where
    liftShowsPrec2 :: (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> K a b
-> ShowS
liftShowsPrec2 sp :: Int -> a -> ShowS
sp _ _ _ d :: Int
d (K x :: a
x) = (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> a -> ShowS
sp "K" Int
d a
x

-- | @since 0.2.4.0
instance (Eq a) => Eq1 (K a) where
    liftEq :: (a -> b -> Bool) -> K a a -> K a b -> Bool
liftEq = (a -> a -> Bool) -> (a -> b -> Bool) -> K a a -> K a b -> Bool
forall (f :: * -> * -> *) a b c d.
Eq2 f =>
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool
liftEq2 a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
-- | @since 0.2.4.0
instance (Ord a) => Ord1 (K a) where
    liftCompare :: (a -> b -> Ordering) -> K a a -> K a b -> Ordering
liftCompare = (a -> a -> Ordering)
-> (a -> b -> Ordering) -> K a a -> K a b -> Ordering
forall (f :: * -> * -> *) a b c d.
Ord2 f =>
(a -> b -> Ordering)
-> (c -> d -> Ordering) -> f a c -> f b d -> Ordering
liftCompare2 a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
-- | @since 0.2.4.0
instance (Read a) => Read1 (K a) where
    liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (K a a)
liftReadsPrec = (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS a)
-> ReadS [a]
-> Int
-> ReadS (K a a)
forall (f :: * -> * -> *) a b.
Read2 f =>
(Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (f a b)
liftReadsPrec2 Int -> ReadS a
forall a. Read a => Int -> ReadS a
readsPrec ReadS [a]
forall a. Read a => ReadS [a]
readList
-- | @since 0.2.4.0
instance (Show a) => Show1 (K a) where
    liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> K a a -> ShowS
liftShowsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> Int
-> K a a
-> ShowS
forall (f :: * -> * -> *) a b.
Show2 f =>
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
forall a. Show a => [a] -> ShowS
showList

-- This have to be implemented manually, K is polykinded.
instance (Eq a) => Eq (K a b) where
    K x :: a
x == :: K a b -> K a b -> Bool
== K y :: a
y = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y
instance (Ord a) => Ord (K a b) where
    compare :: K a b -> K a b -> Ordering
compare (K x :: a
x) (K y :: a
y) = a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare a
x a
y
instance (Read a) => Read (K a b) where
    readsPrec :: Int -> ReadS (K a b)
readsPrec = (String -> ReadS (K a b)) -> Int -> ReadS (K a b)
forall a. (String -> ReadS a) -> Int -> ReadS a
readsData ((String -> ReadS (K a b)) -> Int -> ReadS (K a b))
-> (String -> ReadS (K a b)) -> Int -> ReadS (K a b)
forall a b. (a -> b) -> a -> b
$ (Int -> ReadS a)
-> String -> (a -> K a b) -> String -> ReadS (K a b)
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith Int -> ReadS a
forall a. Read a => Int -> ReadS a
readsPrec "K" a -> K a b
forall k a (b :: k). a -> K a b
K
instance (Show a) => Show (K a b) where
    showsPrec :: Int -> K a b -> ShowS
showsPrec d :: Int
d (K x :: a
x) = (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec "K" Int
d a
x

-- | @since 0.4.0.0
instance Semigroup a => Semigroup (K a b) where
  K x :: a
x <> :: K a b -> K a b -> K a b
<> K y :: a
y = a -> K a b
forall k a (b :: k). a -> K a b
K (a
x a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
y)

-- | @since 0.4.0.0
instance Monoid a => Monoid (K a b) where
  mempty :: K a b
mempty              = a -> K a b
forall k a (b :: k). a -> K a b
K a
forall a. Monoid a => a
mempty
  mappend :: K a b -> K a b -> K a b
mappend (K x :: a
x) (K y :: a
y) = a -> K a b
forall k a (b :: k). a -> K a b
K (a -> a -> a
forall a. Monoid a => a -> a -> a
mappend a
x a
y)

instance Monoid a => Applicative (K a) where
  pure :: a -> K a a
pure _      = a -> K a a
forall k a (b :: k). a -> K a b
K a
forall a. Monoid a => a
mempty
  K x :: a
x <*> :: K a (a -> b) -> K a a -> K a b
<*> K y :: a
y = a -> K a b
forall k a (b :: k). a -> K a b
K (a -> a -> a
forall a. Monoid a => a -> a -> a
mappend a
x a
y)

-- | Extract the contents of a 'K' value.
unK :: K a b -> a
unK :: K a b -> a
unK (K x :: a
x) = a
x

-- | The identity type functor.
--
-- Like 'Data.Functor.Identity.Identity', but with a shorter name.
--
newtype I (a :: Type) = I a
  deriving (a -> I b -> I a
(a -> b) -> I a -> I b
(forall a b. (a -> b) -> I a -> I b)
-> (forall a b. a -> I b -> I a) -> Functor I
forall a b. a -> I b -> I a
forall a b. (a -> b) -> I a -> I b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> I b -> I a
$c<$ :: forall a b. a -> I b -> I a
fmap :: (a -> b) -> I a -> I b
$cfmap :: forall a b. (a -> b) -> I a -> I b
Functor, I a -> Bool
(a -> m) -> I a -> m
(a -> b -> b) -> b -> I a -> b
(forall m. Monoid m => I m -> m)
-> (forall m a. Monoid m => (a -> m) -> I a -> m)
-> (forall m a. Monoid m => (a -> m) -> I a -> m)
-> (forall a b. (a -> b -> b) -> b -> I a -> b)
-> (forall a b. (a -> b -> b) -> b -> I a -> b)
-> (forall b a. (b -> a -> b) -> b -> I a -> b)
-> (forall b a. (b -> a -> b) -> b -> I a -> b)
-> (forall a. (a -> a -> a) -> I a -> a)
-> (forall a. (a -> a -> a) -> I a -> a)
-> (forall a. I a -> [a])
-> (forall a. I a -> Bool)
-> (forall a. I a -> Int)
-> (forall a. Eq a => a -> I a -> Bool)
-> (forall a. Ord a => I a -> a)
-> (forall a. Ord a => I a -> a)
-> (forall a. Num a => I a -> a)
-> (forall a. Num a => I a -> a)
-> Foldable I
forall a. Eq a => a -> I a -> Bool
forall a. Num a => I a -> a
forall a. Ord a => I a -> a
forall m. Monoid m => I m -> m
forall a. I a -> Bool
forall a. I a -> Int
forall a. I a -> [a]
forall a. (a -> a -> a) -> I a -> a
forall m a. Monoid m => (a -> m) -> I a -> m
forall b a. (b -> a -> b) -> b -> I a -> b
forall a b. (a -> b -> b) -> b -> I 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 :: I a -> a
$cproduct :: forall a. Num a => I a -> a
sum :: I a -> a
$csum :: forall a. Num a => I a -> a
minimum :: I a -> a
$cminimum :: forall a. Ord a => I a -> a
maximum :: I a -> a
$cmaximum :: forall a. Ord a => I a -> a
elem :: a -> I a -> Bool
$celem :: forall a. Eq a => a -> I a -> Bool
length :: I a -> Int
$clength :: forall a. I a -> Int
null :: I a -> Bool
$cnull :: forall a. I a -> Bool
toList :: I a -> [a]
$ctoList :: forall a. I a -> [a]
foldl1 :: (a -> a -> a) -> I a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> I a -> a
foldr1 :: (a -> a -> a) -> I a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> I a -> a
foldl' :: (b -> a -> b) -> b -> I a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> I a -> b
foldl :: (b -> a -> b) -> b -> I a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> I a -> b
foldr' :: (a -> b -> b) -> b -> I a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> I a -> b
foldr :: (a -> b -> b) -> b -> I a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> I a -> b
foldMap' :: (a -> m) -> I a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> I a -> m
foldMap :: (a -> m) -> I a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> I a -> m
fold :: I m -> m
$cfold :: forall m. Monoid m => I m -> m
Foldable, Functor I
Foldable I
(Functor I, Foldable I) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> I a -> f (I b))
-> (forall (f :: * -> *) a. Applicative f => I (f a) -> f (I a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> I a -> m (I b))
-> (forall (m :: * -> *) a. Monad m => I (m a) -> m (I a))
-> Traversable I
(a -> f b) -> I a -> f (I 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 => I (m a) -> m (I a)
forall (f :: * -> *) a. Applicative f => I (f a) -> f (I a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> I a -> m (I b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> I a -> f (I b)
sequence :: I (m a) -> m (I a)
$csequence :: forall (m :: * -> *) a. Monad m => I (m a) -> m (I a)
mapM :: (a -> m b) -> I a -> m (I b)
$cmapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> I a -> m (I b)
sequenceA :: I (f a) -> f (I a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => I (f a) -> f (I a)
traverse :: (a -> f b) -> I a -> f (I b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> I a -> f (I b)
$cp2Traversable :: Foldable I
$cp1Traversable :: Functor I
Traversable, (forall x. I a -> Rep (I a) x)
-> (forall x. Rep (I a) x -> I a) -> Generic (I a)
forall x. Rep (I a) x -> I a
forall x. I a -> Rep (I a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (I a) x -> I a
forall a x. I a -> Rep (I a) x
$cto :: forall a x. Rep (I a) x -> I a
$cfrom :: forall a x. I a -> Rep (I a) x
GHC.Generic)

-- | @since 0.4.0.0
instance Semigroup a => Semigroup (I a) where
  I x :: a
x <> :: I a -> I a -> I a
<> I y :: a
y = a -> I a
forall a. a -> I a
I (a
x a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
y)

-- | @since 0.4.0.0
instance Monoid a => Monoid (I a) where
  mempty :: I a
mempty              = a -> I a
forall a. a -> I a
I a
forall a. Monoid a => a
mempty
  mappend :: I a -> I a -> I a
mappend (I x :: a
x) (I y :: a
y) = a -> I a
forall a. a -> I a
I (a -> a -> a
forall a. Monoid a => a -> a -> a
mappend a
x a
y)

instance Applicative I where
  pure :: a -> I a
pure = a -> I a
forall a. a -> I a
I
  I f :: a -> b
f <*> :: I (a -> b) -> I a -> I b
<*> I x :: a
x = b -> I b
forall a. a -> I a
I (a -> b
f a
x)

instance Monad I where
  return :: a -> I a
return = a -> I a
forall a. a -> I a
I
  I x :: a
x >>= :: I a -> (a -> I b) -> I b
>>= f :: a -> I b
f = a -> I b
f a
x


-- | @since 0.2.4.0
instance Eq1 I where
    liftEq :: (a -> b -> Bool) -> I a -> I b -> Bool
liftEq eq :: a -> b -> Bool
eq (I x :: a
x) (I y :: b
y) = a -> b -> Bool
eq a
x b
y
-- | @since 0.2.4.0
instance Ord1 I where
    liftCompare :: (a -> b -> Ordering) -> I a -> I b -> Ordering
liftCompare comp :: a -> b -> Ordering
comp (I x :: a
x) (I y :: b
y) = a -> b -> Ordering
comp a
x b
y
-- | @since 0.2.4.0
instance Read1 I where
    liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (I a)
liftReadsPrec rp :: Int -> ReadS a
rp _ = (String -> ReadS (I a)) -> Int -> ReadS (I a)
forall a. (String -> ReadS a) -> Int -> ReadS a
readsData ((String -> ReadS (I a)) -> Int -> ReadS (I a))
-> (String -> ReadS (I a)) -> Int -> ReadS (I a)
forall a b. (a -> b) -> a -> b
$
         (Int -> ReadS a) -> String -> (a -> I a) -> String -> ReadS (I a)
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith Int -> ReadS a
rp "I" a -> I a
forall a. a -> I a
I
-- | @since 0.2.4.0
instance Show1 I where
    liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> I a -> ShowS
liftShowsPrec sp :: Int -> a -> ShowS
sp _ d :: Int
d (I x :: a
x) = (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> a -> ShowS
sp "I" Int
d a
x

instance (Eq a) => Eq (I a) where == :: I a -> I a -> Bool
(==) = I a -> I a -> Bool
forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
eq1
instance (Ord a) => Ord (I a) where compare :: I a -> I a -> Ordering
compare = I a -> I a -> Ordering
forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
compare1
instance (Read a) => Read (I a) where readsPrec :: Int -> ReadS (I a)
readsPrec = Int -> ReadS (I a)
forall (f :: * -> *) a. (Read1 f, Read a) => Int -> ReadS (f a)
readsPrec1
instance (Show a) => Show (I a) where showsPrec :: Int -> I a -> ShowS
showsPrec = Int -> I a -> ShowS
forall (f :: * -> *) a. (Show1 f, Show a) => Int -> f a -> ShowS
showsPrec1

-- | Extract the contents of an 'I' value.
unI :: I a -> a
unI :: I a -> a
unI (I x :: a
x) = a
x

-- | Composition of functors.
--
-- Like 'Data.Functor.Compose.Compose', but kind-polymorphic
-- and with a shorter name.
--
newtype (:.:) (f :: l -> Type) (g :: k -> l) (p :: k) = Comp (f (g p))
  deriving ((forall x. (:.:) f g p -> Rep ((:.:) f g p) x)
-> (forall x. Rep ((:.:) f g p) x -> (:.:) f g p)
-> Generic ((:.:) f g p)
forall x. Rep ((:.:) f g p) x -> (:.:) f g p
forall x. (:.:) f g p -> Rep ((:.:) f g p) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall l (f :: l -> *) k (g :: k -> l) (p :: k) x.
Rep ((:.:) f g p) x -> (:.:) f g p
forall l (f :: l -> *) k (g :: k -> l) (p :: k) x.
(:.:) f g p -> Rep ((:.:) f g p) x
$cto :: forall l (f :: l -> *) k (g :: k -> l) (p :: k) x.
Rep ((:.:) f g p) x -> (:.:) f g p
$cfrom :: forall l (f :: l -> *) k (g :: k -> l) (p :: k) x.
(:.:) f g p -> Rep ((:.:) f g p) x
GHC.Generic)

infixr 7 :.:

-- | @since 0.4.0.0
instance (Semigroup (f (g x))) => Semigroup ((f :.: g) x) where
  Comp x :: f (g x)
x <> :: (:.:) f g x -> (:.:) f g x -> (:.:) f g x
<> Comp y :: f (g x)
y = f (g x) -> (:.:) f g x
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (f (g x)
x f (g x) -> f (g x) -> f (g x)
forall a. Semigroup a => a -> a -> a
<> f (g x)
y)

-- | @since 0.4.0.0
instance (Monoid (f (g x))) => Monoid ((f :.: g) x) where
  mempty :: (:.:) f g x
mempty                    = f (g x) -> (:.:) f g x
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp f (g x)
forall a. Monoid a => a
mempty
  mappend :: (:.:) f g x -> (:.:) f g x -> (:.:) f g x
mappend (Comp x :: f (g x)
x) (Comp y :: f (g x)
y) = f (g x) -> (:.:) f g x
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (f (g x) -> f (g x) -> f (g x)
forall a. Monoid a => a -> a -> a
mappend f (g x)
x f (g x)
y)

instance (Functor f, Functor g) => Functor (f :.: g) where
  fmap :: (a -> b) -> (:.:) f g a -> (:.:) f g b
fmap f :: a -> b
f (Comp x :: f (g a)
x) = f (g b) -> (:.:) f g b
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp ((g a -> g b) -> f (g a) -> f (g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) f (g a)
x)

-- | @since 0.2.5.0
instance (Applicative f, Applicative g) => Applicative (f :.: g) where
  pure :: a -> (:.:) f g a
pure x :: a
x = f (g a) -> (:.:) f g a
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (g a -> f (g a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> g a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x))
  Comp f :: f (g (a -> b))
f <*> :: (:.:) f g (a -> b) -> (:.:) f g a -> (:.:) f g b
<*> Comp x :: f (g a)
x = f (g b) -> (:.:) f g b
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (g (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) (g (a -> b) -> g a -> g b) -> f (g (a -> b)) -> f (g a -> g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (g (a -> b))
f f (g a -> g b) -> f (g a) -> f (g b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> f (g a)
x)

-- | @since 0.2.5.0
instance (Foldable f, Foldable g) => Foldable (f :.: g) where
  foldMap :: (a -> m) -> (:.:) f g a -> m
foldMap f :: a -> m
f (Comp t :: f (g a)
t) = (g a -> m) -> f (g a) -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap ((a -> m) -> g a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) f (g a)
t

-- | @since 0.2.5.0
instance (Traversable f, Traversable g) => Traversable (f :.: g) where
  traverse :: (a -> f b) -> (:.:) f g a -> f ((:.:) f g b)
traverse f :: a -> f b
f (Comp t :: f (g a)
t) = f (g b) -> (:.:) f g b
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (f (g b) -> (:.:) f g b) -> f (f (g b)) -> f ((:.:) f g b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g a -> f (g b)) -> f (g a) -> f (f (g b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((a -> f b) -> g a -> f (g b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f) f (g a)
t


-- Instances of lifted Prelude classes

-- | @since 0.2.4.0
instance (Eq1 f, Eq1 g) => Eq1 (f :.: g) where
    liftEq :: (a -> b -> Bool) -> (:.:) f g a -> (:.:) f g b -> Bool
liftEq eq :: a -> b -> Bool
eq (Comp x :: f (g a)
x) (Comp y :: f (g b)
y) = (g a -> g b -> Bool) -> f (g a) -> f (g b) -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq ((a -> b -> Bool) -> g a -> g b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq) f (g a)
x f (g b)
y

-- | @since 0.2.4.0
instance (Ord1 f, Ord1 g) => Ord1 (f :.: g) where
    liftCompare :: (a -> b -> Ordering) -> (:.:) f g a -> (:.:) f g b -> Ordering
liftCompare comp :: a -> b -> Ordering
comp (Comp x :: f (g a)
x) (Comp y :: f (g b)
y) =
        (g a -> g b -> Ordering) -> f (g a) -> f (g b) -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare ((a -> b -> Ordering) -> g a -> g b -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
comp) f (g a)
x f (g b)
y

-- | @since 0.2.4.0
instance (Read1 f, Read1 g) => Read1 (f :.: g) where
    liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS ((:.:) f g a)
liftReadsPrec rp :: Int -> ReadS a
rp rl :: ReadS [a]
rl = (String -> ReadS ((:.:) f g a)) -> Int -> ReadS ((:.:) f g a)
forall a. (String -> ReadS a) -> Int -> ReadS a
readsData ((String -> ReadS ((:.:) f g a)) -> Int -> ReadS ((:.:) f g a))
-> (String -> ReadS ((:.:) f g a)) -> Int -> ReadS ((:.:) f g a)
forall a b. (a -> b) -> a -> b
$
        (Int -> ReadS (f (g a)))
-> String
-> (f (g a) -> (:.:) f g a)
-> String
-> ReadS ((:.:) f g a)
forall a t.
(Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith ((Int -> ReadS (g a)) -> ReadS [g a] -> Int -> ReadS (f (g a))
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS (g a)
rp' ReadS [g a]
rl') "Comp" f (g a) -> (:.:) f g a
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp
      where
        rp' :: Int -> ReadS (g a)
rp' = (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (g a)
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl
        rl' :: ReadS [g a]
rl' = (Int -> ReadS a) -> ReadS [a] -> ReadS [g a]
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
liftReadList Int -> ReadS a
rp ReadS [a]
rl

-- | @since 0.2.4.0
instance (Show1 f, Show1 g) => Show1 (f :.: g) where
    liftShowsPrec :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> (:.:) f g a -> ShowS
liftShowsPrec sp :: Int -> a -> ShowS
sp sl :: [a] -> ShowS
sl d :: Int
d (Comp x :: f (g a)
x) =
        (Int -> f (g a) -> ShowS) -> String -> Int -> f (g a) -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith ((Int -> g a -> ShowS)
-> ([g a] -> ShowS) -> Int -> f (g a) -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> g a -> ShowS
sp' [g a] -> ShowS
sl') "Comp" Int
d f (g a)
x
      where
        sp' :: Int -> g a -> ShowS
sp' = (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> g a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl
        sl' :: [g a] -> ShowS
sl' = (Int -> a -> ShowS) -> ([a] -> ShowS) -> [g a] -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS
liftShowList Int -> a -> ShowS
sp [a] -> ShowS
sl

instance (Eq1 f, Eq1 g, Eq a) => Eq ((f :.: g) a) where == :: (:.:) f g a -> (:.:) f g a -> Bool
(==) = (:.:) f g a -> (:.:) f g a -> Bool
forall (f :: * -> *) a. (Eq1 f, Eq a) => f a -> f a -> Bool
eq1
instance (Ord1 f, Ord1 g, Ord a) => Ord ((f :.: g) a) where compare :: (:.:) f g a -> (:.:) f g a -> Ordering
compare = (:.:) f g a -> (:.:) f g a -> Ordering
forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
compare1
instance (Read1 f, Read1 g, Read a) => Read ((f :.: g) a) where readsPrec :: Int -> ReadS ((:.:) f g a)
readsPrec = Int -> ReadS ((:.:) f g a)
forall (f :: * -> *) a. (Read1 f, Read a) => Int -> ReadS (f a)
readsPrec1
instance (Show1 f, Show1 g, Show a) => Show ((f :.: g) a) where showsPrec :: Int -> (:.:) f g a -> ShowS
showsPrec = Int -> (:.:) f g a -> ShowS
forall (f :: * -> *) a. (Show1 f, Show a) => Int -> f a -> ShowS
showsPrec1

-- NFData Instances

-- | @since 0.2.5.0
instance NFData a => NFData (I a) where
    rnf :: I a -> ()
rnf (I x :: a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x

-- | @since 0.2.5.0
instance NFData a => NFData (K a b) where
    rnf :: K a b -> ()
rnf (K x :: a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x

-- | @since 0.2.5.0
instance NFData (f (g a)) => NFData ((f :.: g)  a) where
    rnf :: (:.:) f g a -> ()
rnf (Comp x :: f (g a)
x) = f (g a) -> ()
forall a. NFData a => a -> ()
rnf f (g a)
x

#if MIN_VERSION_deepseq(1,4,3)
-- | @since 0.2.5.0
instance NFData1 I where
    liftRnf :: (a -> ()) -> I a -> ()
liftRnf r :: a -> ()
r (I x :: a
x) = a -> ()
r a
x

-- | @since 0.2.5.0
instance NFData a => NFData1 (K a) where
    liftRnf :: (a -> ()) -> K a a -> ()
liftRnf _ (K x :: a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x

-- | @since 0.2.5.0
instance NFData2 K where
    liftRnf2 :: (a -> ()) -> (b -> ()) -> K a b -> ()
liftRnf2 r :: a -> ()
r _ (K x :: a
x) = a -> ()
r a
x

-- | @since 0.2.5.0
instance (NFData1 f, NFData1 g) => NFData1 (f :.: g) where
    liftRnf :: (a -> ()) -> (:.:) f g a -> ()
liftRnf r :: a -> ()
r (Comp x :: f (g a)
x) = (g a -> ()) -> f (g a) -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf ((a -> ()) -> g a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
r) f (g a)
x
#endif

-- | Extract the contents of a 'Comp' value.
unComp :: (f :.: g) p -> f (g p)
unComp :: (:.:) f g p -> f (g p)
unComp (Comp x :: f (g p)
x) = f (g p)
x

-- * Mapping functions

-- Implementation note:
--
-- All of these functions are just type specializations of
-- 'coerce'. However, we currently still support GHC 7.6
-- which does not support 'coerce', so we write them
-- explicitly.

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapII :: (a -> b) -> I a -> I b
mapII :: (a -> b) -> I a -> I b
mapII = \ f :: a -> b
f (I a :: a
a) -> b -> I b
forall a. a -> I a
I (a -> b
f a
a)
{-# INLINE mapII #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapIK :: (a -> b) -> I a -> K b c
mapIK :: (a -> b) -> I a -> K b c
mapIK = \ f :: a -> b
f (I a :: a
a) -> b -> K b c
forall k a (b :: k). a -> K a b
K (a -> b
f a
a)
{-# INLINE mapIK #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKI :: (a -> b) -> K a c -> I b
mapKI :: (a -> b) -> K a c -> I b
mapKI = \ f :: a -> b
f (K a :: a
a) -> b -> I b
forall a. a -> I a
I (a -> b
f a
a)
{-# INLINE mapKI #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKK :: (a -> b) -> K a c -> K b d
mapKK :: (a -> b) -> K a c -> K b d
mapKK = \ f :: a -> b
f (K a :: a
a) -> b -> K b d
forall k a (b :: k). a -> K a b
K (a -> b
f a
a)
{-# INLINE mapKK #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapIII :: (a -> b -> c) -> I a -> I b -> I c
mapIII :: (a -> b -> c) -> I a -> I b -> I c
mapIII = \ f :: a -> b -> c
f (I a :: a
a) (I b :: b
b) -> c -> I c
forall a. a -> I a
I (a -> b -> c
f a
a b
b)
{-# INLINE mapIII #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapIIK :: (a -> b -> c) -> I a -> I b -> K c d
mapIIK :: (a -> b -> c) -> I a -> I b -> K c d
mapIIK = \ f :: a -> b -> c
f (I a :: a
a) (I b :: b
b) -> c -> K c d
forall k a (b :: k). a -> K a b
K (a -> b -> c
f a
a b
b)
{-# INLINE mapIIK #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapIKI :: (a -> b -> c) -> I a -> K b d -> I c
mapIKI :: (a -> b -> c) -> I a -> K b d -> I c
mapIKI = \ f :: a -> b -> c
f (I a :: a
a) (K b :: b
b) -> c -> I c
forall a. a -> I a
I (a -> b -> c
f a
a b
b)
{-# INLINE mapIKI #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapIKK :: (a -> b -> c) -> I a -> K b d -> K c e
mapIKK :: (a -> b -> c) -> I a -> K b d -> K c e
mapIKK = \ f :: a -> b -> c
f (I a :: a
a) (K b :: b
b) -> c -> K c e
forall k a (b :: k). a -> K a b
K (a -> b -> c
f a
a b
b)
{-# INLINE mapIKK #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKII :: (a -> b -> c) -> K a d -> I b -> I c
mapKII :: (a -> b -> c) -> K a d -> I b -> I c
mapKII = \ f :: a -> b -> c
f (K a :: a
a) (I b :: b
b) -> c -> I c
forall a. a -> I a
I (a -> b -> c
f a
a b
b)
{-# INLINE mapKII #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKIK :: (a -> b -> c) -> K a d -> I b -> K c e
mapKIK :: (a -> b -> c) -> K a d -> I b -> K c e
mapKIK = \ f :: a -> b -> c
f (K a :: a
a) (I b :: b
b) -> c -> K c e
forall k a (b :: k). a -> K a b
K (a -> b -> c
f a
a b
b)
{-# INLINE mapKIK #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKKI :: (a -> b -> c) -> K a d -> K b e -> I c
mapKKI :: (a -> b -> c) -> K a d -> K b e -> I c
mapKKI = \ f :: a -> b -> c
f (K a :: a
a) (K b :: b
b) -> c -> I c
forall a. a -> I a
I (a -> b -> c
f a
a b
b)
{-# INLINE mapKKI #-}

-- | Lift the given function.
--
-- @since 0.2.5.0
--
mapKKK :: (a -> b -> c) -> K a d -> K b e -> K c f
mapKKK :: (a -> b -> c) -> K a d -> K b e -> K c f
mapKKK = \ f :: a -> b -> c
f (K a :: a
a) (K b :: b
b) -> c -> K c f
forall k a (b :: k). a -> K a b
K (a -> b -> c
f a
a b
b)
{-# INLINE mapKKK #-}