Movatterモバイル変換
[0]ホーム
{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE Safe #-}------------------------------------------------------------------------------- |-- Module : Data.Functor.Product-- Copyright : (c) Ross Paterson 2010-- License : BSD-style (see the file LICENSE)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable---- Products, lifted to functors.---- @since 4.9.0.0-----------------------------------------------------------------------------moduleData.Functor.Product(Product(..),)whereimportControl.ApplicativeimportControl.Monad(MonadPlus(..))importControl.Monad.Fix(MonadFix(..))importControl.Monad.Zip(MonadZip(mzipWith))importData.Data(Data)importData.Foldable(Foldable(foldMap))importData.Functor.ClassesimportData.Monoid(mappend)importData.Traversable(Traversable(traverse))importGHC.Generics(Generic,Generic1)importText.Read(Read(..),readListDefault,readListPrecDefault)-- | Lifted product of functors.dataProductfga=Pair(fa)(ga)deriving(Data-- ^ @since 4.9.0.0,Generic-- ^ @since 4.9.0.0,Generic1-- ^ @since 4.9.0.0)-- | @since 4.9.0.0instance(Eq1f,Eq1g)=>Eq1(Productfg)whereliftEqeq(Pairx1y1)(Pairx2y2)=liftEqeqx1x2&&liftEqeqy1y2-- | @since 4.9.0.0instance(Ord1f,Ord1g)=>Ord1(Productfg)whereliftComparecomp(Pairx1y1)(Pairx2y2)=liftComparecompx1x2`mappend`liftComparecompy1y2-- | @since 4.9.0.0instance(Read1f,Read1g)=>Read1(Productfg)whereliftReadPrecrprl=readData$readBinaryWith(liftReadPrecrprl)(liftReadPrecrprl)"Pair"PairliftReadListPrec=liftReadListPrecDefaultliftReadList=liftReadListDefault-- | @since 4.9.0.0instance(Show1f,Show1g)=>Show1(Productfg)whereliftShowsPrecspsld(Pairxy)=showsBinaryWith(liftShowsPrecspsl)(liftShowsPrecspsl)"Pair"dxy-- | @since 4.9.0.0instance(Eq1f,Eq1g,Eqa)=>Eq(Productfga)where(==)=eq1-- | @since 4.9.0.0instance(Ord1f,Ord1g,Orda)=>Ord(Productfga)wherecompare=compare1-- | @since 4.9.0.0instance(Read1f,Read1g,Reada)=>Read(Productfga)wherereadPrec=readPrec1readListPrec=readListPrecDefaultreadList=readListDefault-- | @since 4.9.0.0instance(Show1f,Show1g,Showa)=>Show(Productfga)whereshowsPrec=showsPrec1-- | @since 4.9.0.0instance(Functorf,Functorg)=>Functor(Productfg)wherefmapf(Pairxy)=Pair(fmapfx)(fmapfy)-- | @since 4.9.0.0instance(Foldablef,Foldableg)=>Foldable(Productfg)wherefoldMapf(Pairxy)=foldMapfx`mappend`foldMapfy-- | @since 4.9.0.0instance(Traversablef,Traversableg)=>Traversable(Productfg)wheretraversef(Pairxy)=liftA2Pair(traversefx)(traversefy)-- | @since 4.9.0.0instance(Applicativef,Applicativeg)=>Applicative(Productfg)wherepurex=Pair(purex)(purex)Pairfg<*>Pairxy=Pair(f<*>x)(g<*>y)liftA2f(Pairab)(Pairxy)=Pair(liftA2fax)(liftA2fby)-- | @since 4.9.0.0instance(Alternativef,Alternativeg)=>Alternative(Productfg)whereempty=PairemptyemptyPairx1y1<|>Pairx2y2=Pair(x1<|>x2)(y1<|>y2)-- | @since 4.9.0.0instance(Monadf,Monadg)=>Monad(Productfg)wherePairmn>>=f=Pair(m>>=fstP.f)(n>>=sndP.f)wherefstP(Paira_)=asndP(Pair_b)=b-- | @since 4.9.0.0instance(MonadPlusf,MonadPlusg)=>MonadPlus(Productfg)wheremzero=PairmzeromzeroPairx1y1`mplus`Pairx2y2=Pair(x1`mplus`x2)(y1`mplus`y2)-- | @since 4.9.0.0instance(MonadFixf,MonadFixg)=>MonadFix(Productfg)wheremfixf=Pair(mfix(fstP.f))(mfix(sndP.f))wherefstP(Paira_)=asndP(Pair_b)=b-- | @since 4.9.0.0instance(MonadZipf,MonadZipg)=>MonadZip(Productfg)wheremzipWithf(Pairx1y1)(Pairx2y2)=Pair(mzipWithfx1x2)(mzipWithfy1y2)
[8]ページ先頭