swap <[]> and <{}> syntax
[ghc-hetmet.git] / compiler / utils / Pair.lhs
index eb594af..9e847d6 100644 (file)
@@ -1,47 +1,47 @@
-\r
-A simple homogeneous pair type with useful Functor, Applicative, and\r
-Traversable instances.\r
-\r
-\begin{code}\r
-module Pair ( Pair(..), unPair, toPair, swap ) where\r
-\r
-#include "HsVersions.h"\r
-\r
-import Outputable\r
-import Data.Monoid\r
-import Control.Applicative\r
-import Data.Foldable\r
-import Data.Traversable\r
-\r
-data Pair a = Pair { pFst :: a, pSnd :: a }\r
--- Note that Pair is a *unary* type constructor\r
--- whereas (,) is binary\r
-\r
--- The important thing about Pair is that it has a *homogenous*\r
--- Functor instance, so you can easily apply the same function\r
--- to both components\r
-instance Functor Pair where\r
-  fmap f (Pair x y) = Pair (f x) (f y)\r
-\r
-instance Applicative Pair where\r
-  pure x = Pair x x\r
-  (Pair f g) <*> (Pair x y) = Pair (f x) (g y)\r
-\r
-instance Foldable Pair where\r
-  foldMap f (Pair x y) = f x `mappend` f y\r
-\r
-instance Traversable Pair where\r
-  traverse f (Pair x y) = Pair <$> f x <*> f y\r
-\r
-instance Outputable a => Outputable (Pair a) where\r
-  ppr (Pair a b) = ppr a <+> char '~' <+> ppr b\r
-\r
-unPair :: Pair a -> (a,a)\r
-unPair (Pair x y) = (x,y)\r
-\r
-toPair :: (a,a) -> Pair a\r
-toPair (x,y) = Pair x y\r
-\r
-swap :: Pair a -> Pair a\r
-swap (Pair x y) = Pair y x\r
+
+A simple homogeneous pair type with useful Functor, Applicative, and
+Traversable instances.
+
+\begin{code}
+module Pair ( Pair(..), unPair, toPair, swap ) where
+
+#include "HsVersions.h"
+
+import Outputable
+import Data.Monoid
+import Control.Applicative
+import Data.Foldable
+import Data.Traversable
+
+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*
+-- Functor instance, so you can easily apply the same function
+-- to both components
+instance Functor Pair where
+  fmap f (Pair x y) = Pair (f x) (f y)
+
+instance Applicative Pair where
+  pure x = Pair x x
+  (Pair f g) <*> (Pair x y) = Pair (f x) (g y)
+
+instance Foldable Pair where
+  foldMap f (Pair x y) = f x `mappend` f y
+
+instance Traversable Pair where
+  traverse f (Pair x y) = Pair <$> f x <*> f y
+
+instance Outputable a => Outputable (Pair a) where
+  ppr (Pair a b) = ppr a <+> char '~' <+> ppr b
+
+unPair :: Pair a -> (a,a)
+unPair (Pair x y) = (x,y)
+
+toPair :: (a,a) -> Pair a
+toPair (x,y) = Pair x y
+
+swap :: Pair a -> Pair a
+swap (Pair x y) = Pair y x
 \end{code}
\ No newline at end of file