summaryrefslogtreecommitdiff
path: root/compiler/utils/Pair.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils/Pair.hs')
-rw-r--r--compiler/utils/Pair.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/utils/Pair.hs b/compiler/utils/Pair.hs
index b33ccbac06..8747e619ca 100644
--- a/compiler/utils/Pair.hs
+++ b/compiler/utils/Pair.hs
@@ -5,7 +5,7 @@ Traversable instances.
{-# LANGUAGE CPP #-}
-module Pair ( Pair(..), unPair, toPair, swap ) where
+module Pair ( Pair(..), unPair, toPair, swap, pLiftFst, pLiftSnd ) where
#include "HsVersions.h"
@@ -37,6 +37,10 @@ instance Foldable Pair where
instance Traversable Pair where
traverse f (Pair x y) = Pair <$> f x <*> f y
+instance Monoid a => Monoid (Pair a) where
+ mempty = Pair mempty mempty
+ Pair a1 b1 `mappend` Pair a2 b2 = Pair (a1 `mappend` a2) (b1 `mappend` b2)
+
instance Outputable a => Outputable (Pair a) where
ppr (Pair a b) = ppr a <+> char '~' <+> ppr b
@@ -48,3 +52,9 @@ toPair (x,y) = Pair x y
swap :: Pair a -> Pair a
swap (Pair x y) = Pair y x
+
+pLiftFst :: (a -> a) -> Pair a -> Pair a
+pLiftFst f (Pair a b) = Pair (f a) b
+
+pLiftSnd :: (a -> a) -> Pair a -> Pair a
+pLiftSnd f (Pair a b) = Pair a (f b)