{-# LANGUAGE DeriveTraversable #-}
module GHC.Data.Pair
( Pair(..)
, unPair
, toPair
, swap
, pLiftFst
, pLiftSnd
)
where
import GHC.Prelude
import GHC.Utils.Outputable
import qualified Data.Semigroup as Semi
data Pair a = Pair { forall a. Pair a -> a
pFst :: a, forall a. Pair a -> a
pSnd :: a }
deriving (forall a. Eq a => a -> Pair a -> Bool
forall a. Num a => Pair a -> a
forall a. Ord a => Pair a -> a
forall m. Monoid m => Pair m -> m
forall a. Pair a -> Bool
forall a. Pair a -> Int
forall a. Pair a -> [a]
forall a. (a -> a -> a) -> Pair a -> a
forall m a. Monoid m => (a -> m) -> Pair a -> m
forall b a. (b -> a -> b) -> b -> Pair a -> b
forall a b. (a -> b -> b) -> b -> Pair a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Pair a -> a
$cproduct :: forall a. Num a => Pair a -> a
sum :: forall a. Num a => Pair a -> a
$csum :: forall a. Num a => Pair a -> a
minimum :: forall a. Ord a => Pair a -> a
$cminimum :: forall a. Ord a => Pair a -> a
maximum :: forall a. Ord a => Pair a -> a
$cmaximum :: forall a. Ord a => Pair a -> a
elem :: forall a. Eq a => a -> Pair a -> Bool
$celem :: forall a. Eq a => a -> Pair a -> Bool
length :: forall a. Pair a -> Int
$clength :: forall a. Pair a -> Int
null :: forall a. Pair a -> Bool
$cnull :: forall a. Pair a -> Bool
toList :: forall a. Pair a -> [a]
$ctoList :: forall a. Pair a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Pair a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Pair a -> a
foldr1 :: forall a. (a -> a -> a) -> Pair a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Pair a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Pair a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Pair a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Pair a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Pair a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Pair a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Pair a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Pair a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Pair a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Pair a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Pair a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Pair a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Pair a -> m
fold :: forall m. Monoid m => Pair m -> m
$cfold :: forall m. Monoid m => Pair m -> m
Foldable, forall a b. a -> Pair b -> Pair a
forall a b. (a -> b) -> Pair a -> Pair b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Pair b -> Pair a
$c<$ :: forall a b. a -> Pair b -> Pair a
fmap :: forall a b. (a -> b) -> Pair a -> Pair b
$cfmap :: forall a b. (a -> b) -> Pair a -> Pair b
Functor, Functor Pair
Foldable Pair
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 => Pair (m a) -> m (Pair a)
forall (f :: * -> *) a. Applicative f => Pair (f a) -> f (Pair a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pair a -> m (Pair b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pair a -> f (Pair b)
sequence :: forall (m :: * -> *) a. Monad m => Pair (m a) -> m (Pair a)
$csequence :: forall (m :: * -> *) a. Monad m => Pair (m a) -> m (Pair a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pair a -> m (Pair b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Pair a -> m (Pair b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Pair (f a) -> f (Pair a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Pair (f a) -> f (Pair a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pair a -> f (Pair b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Pair a -> f (Pair b)
Traversable)
instance Applicative Pair where
pure :: forall a. a -> Pair a
pure a
x = forall a. a -> a -> Pair a
Pair a
x a
x
(Pair a -> b
f a -> b
g) <*> :: forall a b. Pair (a -> b) -> Pair a -> Pair b
<*> (Pair a
x a
y) = forall a. a -> a -> Pair a
Pair (a -> b
f a
x) (a -> b
g a
y)
instance Semi.Semigroup a => Semi.Semigroup (Pair a) where
Pair a
a1 a
b1 <> :: Pair a -> Pair a -> Pair a
<> Pair a
a2 a
b2 = forall a. a -> a -> Pair a
Pair (a
a1 forall a. Semigroup a => a -> a -> a
Semi.<> a
a2) (a
b1 forall a. Semigroup a => a -> a -> a
Semi.<> a
b2)
instance (Semi.Semigroup a, Monoid a) => Monoid (Pair a) where
mempty :: Pair a
mempty = forall a. a -> a -> Pair a
Pair forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty
mappend :: Pair a -> Pair a -> Pair a
mappend = forall a. Semigroup a => a -> a -> a
(Semi.<>)
instance Outputable a => Outputable (Pair a) where
ppr :: Pair a -> SDoc
ppr (Pair a
a a
b) = forall a. Outputable a => a -> SDoc
ppr a
a forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Char -> doc
char Char
'~' forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr a
b
unPair :: Pair a -> (a,a)
unPair :: forall a. Pair a -> (a, a)
unPair (Pair a
x a
y) = (a
x,a
y)
toPair :: (a,a) -> Pair a
toPair :: forall a. (a, a) -> Pair a
toPair (a
x,a
y) = forall a. a -> a -> Pair a
Pair a
x a
y
swap :: Pair a -> Pair a
swap :: forall a. Pair a -> Pair a
swap (Pair a
x a
y) = forall a. a -> a -> Pair a
Pair a
y a
x
pLiftFst :: (a -> a) -> Pair a -> Pair a
pLiftFst :: forall a. (a -> a) -> Pair a -> Pair a
pLiftFst a -> a
f (Pair a
a a
b) = forall a. a -> a -> Pair a
Pair (a -> a
f a
a) a
b
pLiftSnd :: (a -> a) -> Pair a -> Pair a
pLiftSnd :: forall a. (a -> a) -> Pair a -> Pair a
pLiftSnd a -> a
f (Pair a
a a
b) = forall a. a -> a -> Pair a
Pair a
a (a -> a
f a
b)