diff options
author | Kavon Farvardin <kavon@farvard.in> | 2018-09-23 15:29:37 -0500 |
---|---|---|
committer | Kavon Farvardin <kavon@farvard.in> | 2018-09-23 15:29:37 -0500 |
commit | 84c2ad99582391005b5e873198b15e9e9eb4f78d (patch) | |
tree | caa8c2f2ec7e97fbb4977263c6817c9af5025cf4 /compiler/utils/Pair.hs | |
parent | 8ddb47cfcf5776e9a3c55fd37947c8a95e00fa12 (diff) | |
parent | e68b439fe5de61b9a2ca51af472185c62ccb8b46 (diff) | |
download | haskell-wip/T13904.tar.gz |
update to current master againwip/T13904
Diffstat (limited to 'compiler/utils/Pair.hs')
-rw-r--r-- | compiler/utils/Pair.hs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/utils/Pair.hs b/compiler/utils/Pair.hs index d816ad3f98..036dab062d 100644 --- a/compiler/utils/Pair.hs +++ b/compiler/utils/Pair.hs @@ -9,13 +9,16 @@ module Pair ( Pair(..), unPair, toPair, swap, pLiftFst, pLiftSnd ) where #include "HsVersions.h" +import GhcPrelude + import Outputable +import qualified Data.Semigroup as Semi data Pair a = Pair { pFst :: a, pSnd :: a } -- Note that Pair is a *unary* type constructor -- whereas (,) is binary --- The important thing about Pair is that it has a *homogenous* +-- The important thing about Pair is that it has a *homogeneous* -- Functor instance, so you can easily apply the same function -- to both components instance Functor Pair where @@ -31,9 +34,12 @@ 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 +instance Semi.Semigroup a => Semi.Semigroup (Pair a) where + Pair a1 b1 <> Pair a2 b2 = Pair (a1 Semi.<> a2) (b1 Semi.<> b2) + +instance (Semi.Semigroup a, Monoid a) => Monoid (Pair a) where mempty = Pair mempty mempty - Pair a1 b1 `mappend` Pair a2 b2 = Pair (a1 `mappend` a2) (b1 `mappend` b2) + mappend = (Semi.<>) instance Outputable a => Outputable (Pair a) where ppr (Pair a b) = ppr a <+> char '~' <+> ppr b |