{-# LANGUAGE PolyKinds, DeriveGeneric #-}
module Data.SOP.BasicFunctors
(
K(..)
, unK
, I(..)
, unI
, (:.:)(..)
, unComp
, mapII
, mapIK
, mapKI
, mapKK
, mapIII
, mapIIK
, mapIKI
, mapIKK
, mapKII
, mapKIK
, mapKKI
, mapKKK
) where
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup (Semigroup (..))
#endif
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
import Data.Coerce (coerce)
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)
instance Eq2 K where
liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> K a c -> K b d -> Bool
liftEq2 a -> b -> Bool
eq c -> d -> Bool
_ (K a
x) (K b
y) = a -> b -> Bool
eq a
x b
y
instance Ord2 K where
liftCompare2 :: (a -> b -> Ordering)
-> (c -> d -> Ordering) -> K a c -> K b d -> Ordering
liftCompare2 a -> b -> Ordering
comp c -> d -> Ordering
_ (K a
x) (K b
y) = a -> b -> Ordering
comp a
x b
y
instance Read2 K where
liftReadsPrec2 :: (Int -> ReadS a)
-> ReadS [a]
-> (Int -> ReadS b)
-> ReadS [b]
-> Int
-> ReadS (K a b)
liftReadsPrec2 Int -> ReadS a
rp ReadS [a]
_ Int -> ReadS b
_ ReadS [b]
_ = (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 String
"K" a -> K a b
forall k a (b :: k). a -> K a b
K
instance Show2 K where
liftShowsPrec2 :: (Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> K a b
-> ShowS
liftShowsPrec2 Int -> a -> ShowS
sp [a] -> ShowS
_ Int -> b -> ShowS
_ [b] -> ShowS
_ Int
d (K a
x) = (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> a -> ShowS
sp String
"K" Int
d a
x
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
(==)
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
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
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
instance (Eq a) => Eq (K a b) where
K a
x == :: K a b -> K a b -> Bool
== K 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 a
x) (K 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 String
"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 Int
d (K 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 String
"K" Int
d a
x
instance Semigroup a => Semigroup (K a b) where
K a
x <> :: K a b -> K a b -> K a b
<> K 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)
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
#if !MIN_VERSION_base(4,11,0)
mappend (K x) (K y) = K (mappend x y)
#endif
instance Monoid a => Applicative (K a) where
pure :: a -> K a a
pure a
_ = a -> K a a
forall k a (b :: k). a -> K a b
K a
forall a. Monoid a => a
mempty
K a
x <*> :: K a (a -> b) -> K a a -> K a b
<*> K 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)
unK :: K a b -> a
unK :: K a b -> a
unK (K a
x) = a
x
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)
instance Semigroup a => Semigroup (I a) where
I a
x <> :: I a -> I a -> I a
<> I 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)
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
#if !MIN_VERSION_base(4,11,0)
mappend (I x) (I y) = I (mappend x y)
#endif
instance Applicative I where
pure :: a -> I a
pure = a -> I a
forall a. a -> I a
I
I a -> b
f <*> :: I (a -> b) -> I a -> I b
<*> I a
x = b -> I b
forall a. a -> I a
I (a -> b
f a
x)
instance Monad I where
I a
x >>= :: I a -> (a -> I b) -> I b
>>= a -> I b
f = a -> I b
f a
x
instance Eq1 I where
liftEq :: (a -> b -> Bool) -> I a -> I b -> Bool
liftEq a -> b -> Bool
eq (I a
x) (I b
y) = a -> b -> Bool
eq a
x b
y
instance Ord1 I where
liftCompare :: (a -> b -> Ordering) -> I a -> I b -> Ordering
liftCompare a -> b -> Ordering
comp (I a
x) (I b
y) = a -> b -> Ordering
comp a
x b
y
instance Read1 I where
liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (I a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
_ = (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 String
"I" a -> I a
forall a. a -> I a
I
instance Show1 I where
liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> I a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
_ Int
d (I a
x) = (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
forall a. (Int -> a -> ShowS) -> String -> Int -> a -> ShowS
showsUnaryWith Int -> a -> ShowS
sp String
"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
unI :: I a -> a
unI :: I a -> a
unI (I a
x) = a
x
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 :.:
instance (Semigroup (f (g x))) => Semigroup ((f :.: g) x) where
Comp f (g x)
x <> :: (:.:) f g x -> (:.:) f g x -> (:.:) f g x
<> Comp 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)
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
#if !MIN_VERSION_base(4,11,0)
mappend (Comp x) (Comp y) = Comp (mappend x y)
#endif
instance (Functor f, Functor g) => Functor (f :.: g) where
fmap :: (a -> b) -> (:.:) f g a -> (:.:) f g b
fmap a -> b
f (Comp 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)
instance (Applicative f, Applicative g) => Applicative (f :.: g) where
pure :: a -> (:.:) f g a
pure 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 (g (a -> b))
f <*> :: (:.:) f g (a -> b) -> (:.:) f g a -> (:.:) f g b
<*> Comp 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)
instance (Foldable f, Foldable g) => Foldable (f :.: g) where
foldMap :: (a -> m) -> (:.:) f g a -> m
foldMap a -> m
f (Comp 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
instance (Traversable f, Traversable g) => Traversable (f :.: g) where
traverse :: (a -> f b) -> (:.:) f g a -> f ((:.:) f g b)
traverse a -> f b
f (Comp 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
instance (Eq1 f, Eq1 g) => Eq1 (f :.: g) where
liftEq :: (a -> b -> Bool) -> (:.:) f g a -> (:.:) f g b -> Bool
liftEq a -> b -> Bool
eq (Comp f (g a)
x) (Comp 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
instance (Ord1 f, Ord1 g) => Ord1 (f :.: g) where
liftCompare :: (a -> b -> Ordering) -> (:.:) f g a -> (:.:) f g b -> Ordering
liftCompare a -> b -> Ordering
comp (Comp f (g a)
x) (Comp 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
instance (Read1 f, Read1 g) => Read1 (f :.: g) where
liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS ((:.:) f g a)
liftReadsPrec Int -> ReadS a
rp 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') String
"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
instance (Show1 f, Show1 g) => Show1 (f :.: g) where
liftShowsPrec :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> (:.:) f g a -> ShowS
liftShowsPrec Int -> a -> ShowS
sp [a] -> ShowS
sl Int
d (Comp 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') String
"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
instance NFData a => NFData (I a) where
rnf :: I a -> ()
rnf (I a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x
instance NFData a => NFData (K a b) where
rnf :: K a b -> ()
rnf (K a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x
instance NFData (f (g a)) => NFData ((f :.: g) a) where
rnf :: (:.:) f g a -> ()
rnf (Comp f (g a)
x) = f (g a) -> ()
forall a. NFData a => a -> ()
rnf f (g a)
x
#if MIN_VERSION_deepseq(1,4,3)
instance NFData1 I where
liftRnf :: (a -> ()) -> I a -> ()
liftRnf a -> ()
r (I a
x) = a -> ()
r a
x
instance NFData a => NFData1 (K a) where
liftRnf :: (a -> ()) -> K a a -> ()
liftRnf a -> ()
_ (K a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x
instance NFData2 K where
liftRnf2 :: (a -> ()) -> (b -> ()) -> K a b -> ()
liftRnf2 a -> ()
r b -> ()
_ (K a
x) = a -> ()
r a
x
instance (NFData1 f, NFData1 g) => NFData1 (f :.: g) where
liftRnf :: (a -> ()) -> (:.:) f g a -> ()
liftRnf a -> ()
r (Comp 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
unComp :: (f :.: g) p -> f (g p)
unComp :: (:.:) f g p -> f (g p)
unComp (Comp f (g p)
x) = f (g p)
x
mapII :: (a -> b) -> I a -> I b
mapII :: (a -> b) -> I a -> I b
mapII = (a -> b) -> I a -> I b
coerce
{-# INLINE mapII #-}
mapIK :: (a -> b) -> I a -> K b c
mapIK :: (a -> b) -> I a -> K b c
mapIK = (a -> b) -> I a -> K b c
coerce
{-# INLINE mapIK #-}
mapKI :: (a -> b) -> K a c -> I b
mapKI :: (a -> b) -> K a c -> I b
mapKI = (a -> b) -> K a c -> I b
coerce
{-# INLINE mapKI #-}
mapKK :: (a -> b) -> K a c -> K b d
mapKK :: (a -> b) -> K a c -> K b d
mapKK = (a -> b) -> K a c -> K b d
coerce
{-# INLINE mapKK #-}
mapIII :: (a -> b -> c) -> I a -> I b -> I c
mapIII :: (a -> b -> c) -> I a -> I b -> I c
mapIII = (a -> b -> c) -> I a -> I b -> I c
coerce
{-# INLINE mapIII #-}
mapIIK :: (a -> b -> c) -> I a -> I b -> K c d
mapIIK :: (a -> b -> c) -> I a -> I b -> K c d
mapIIK = (a -> b -> c) -> I a -> I b -> K c d
coerce
{-# INLINE mapIIK #-}
mapIKI :: (a -> b -> c) -> I a -> K b d -> I c
mapIKI :: (a -> b -> c) -> I a -> K b d -> I c
mapIKI = (a -> b -> c) -> I a -> K b d -> I c
coerce
{-# INLINE mapIKI #-}
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 = (a -> b -> c) -> I a -> K b d -> K c e
coerce
{-# INLINE mapIKK #-}
mapKII :: (a -> b -> c) -> K a d -> I b -> I c
mapKII :: (a -> b -> c) -> K a d -> I b -> I c
mapKII = (a -> b -> c) -> K a d -> I b -> I c
coerce
{-# INLINE mapKII #-}
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 = (a -> b -> c) -> K a d -> I b -> K c e
coerce
{-# INLINE mapKIK #-}
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 = (a -> b -> c) -> K a d -> K b e -> I c
coerce
{-# INLINE mapKKI #-}
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 = (a -> b -> c) -> K a d -> K b e -> K c f
coerce
{-# INLINE mapKKK #-}