{-
A simple homogeneous pair type with useful Functor, Applicative, and
Traversable instances.
-}{-# LANGUAGE CPP #-}modulePair(Pair (..),unPair ,toPair ,swap ,pLiftFst ,pLiftSnd )where#include "HsVersions.h"
importGhcPrelude importOutputable importqualifiedData.SemigroupasSemidataPair 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 *homogeneous*-- Functor instance, so you can easily apply the same function-- to both componentsinstanceFunctorPair wherefmap f (Pair x y )=Pair (f x )(f y )instanceApplicativePair wherepure x =Pair x x (Pair f g )<*> (Pair x y )=Pair (f x )(g y )instanceFoldablePair wherefoldMap f (Pair x y )=f x `mappend`f y instanceTraversablePair wheretraverse f (Pair x y )=Pair <$>f x <*>f y instanceSemi.Semigroupa =>Semi.Semigroup(Pair a )wherePair a1 b1 <> Pair a2 b2 =Pair (a1 Semi.<>a2 )(b1 Semi.<>b2 )instance(Semi.Semigroupa ,Monoida )=>Monoid(Pair a )wheremempty =Pair memptymemptymappend =(Semi.<>)instanceOutputable a =>Outputable (Pair a )whereppr (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 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 )

AltStyle によって変換されたページ (->オリジナル) /