Movatterモバイル変換
[0]ホーム
{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE Safe #-}------------------------------------------------------------------------------- |-- Module : Data.Functor.Sum-- Copyright : (c) Ross Paterson 2014-- License : BSD-style (see the file LICENSE)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable---- Sums, lifted to functors.---- @since 4.9.0.0-----------------------------------------------------------------------------moduleData.Functor.Sum(Sum(..),)whereimportControl.Applicative((<|>))importData.Data(Data)importData.Foldable(Foldable(foldMap))importData.Functor.ClassesimportData.Traversable(Traversable(traverse))importGHC.Generics(Generic,Generic1)importText.Read(Read(..),readListDefault,readListPrecDefault)-- | Lifted sum of functors.dataSumfga=InL(fa)|InR(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(Sumfg)whereliftEqeq(InLx1)(InLx2)=liftEqeqx1x2liftEq_(InL_)(InR_)=FalseliftEq_(InR_)(InL_)=FalseliftEqeq(InRy1)(InRy2)=liftEqeqy1y2-- | @since 4.9.0.0instance(Ord1f,Ord1g)=>Ord1(Sumfg)whereliftComparecomp(InLx1)(InLx2)=liftComparecompx1x2liftCompare_(InL_)(InR_)=LTliftCompare_(InR_)(InL_)=GTliftComparecomp(InRy1)(InRy2)=liftComparecompy1y2-- | @since 4.9.0.0instance(Read1f,Read1g)=>Read1(Sumfg)whereliftReadPrecrprl=readData$readUnaryWith(liftReadPrecrprl)"InL"InL<|>readUnaryWith(liftReadPrecrprl)"InR"InRliftReadListPrec=liftReadListPrecDefaultliftReadList=liftReadListDefault-- | @since 4.9.0.0instance(Show1f,Show1g)=>Show1(Sumfg)whereliftShowsPrecspsld(InLx)=showsUnaryWith(liftShowsPrecspsl)"InL"dxliftShowsPrecspsld(InRy)=showsUnaryWith(liftShowsPrecspsl)"InR"dy-- | @since 4.9.0.0instance(Eq1f,Eq1g,Eqa)=>Eq(Sumfga)where(==)=eq1-- | @since 4.9.0.0instance(Ord1f,Ord1g,Orda)=>Ord(Sumfga)wherecompare=compare1-- | @since 4.9.0.0instance(Read1f,Read1g,Reada)=>Read(Sumfga)wherereadPrec=readPrec1readListPrec=readListPrecDefaultreadList=readListDefault-- | @since 4.9.0.0instance(Show1f,Show1g,Showa)=>Show(Sumfga)whereshowsPrec=showsPrec1-- | @since 4.9.0.0instance(Functorf,Functorg)=>Functor(Sumfg)wherefmapf(InLx)=InL(fmapfx)fmapf(InRy)=InR(fmapfy)-- | @since 4.9.0.0instance(Foldablef,Foldableg)=>Foldable(Sumfg)wherefoldMapf(InLx)=foldMapfxfoldMapf(InRy)=foldMapfy-- | @since 4.9.0.0instance(Traversablef,Traversableg)=>Traversable(Sumfg)wheretraversef(InLx)=InL<$>traversefxtraversef(InRy)=InR<$>traversefy
[8]ページ先頭