Movatterモバイル変換
[0]ホーム
{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE Trustworthy #-}------------------------------------------------------------------------------- |-- Module : Data.Functor.Compose-- Copyright : (c) Ross Paterson 2010-- License : BSD-style (see the file LICENSE)---- Maintainer : libraries@haskell.org-- Stability : experimental-- Portability : portable---- Composition of functors.---- @since 4.9.0.0-----------------------------------------------------------------------------moduleData.Functor.Compose(Compose(..),)whereimportData.Functor.ClassesimportControl.ApplicativeimportData.Coerce(coerce)importData.Data(Data)importData.Foldable(Foldable(foldMap))importData.Traversable(Traversable(traverse))importGHC.Generics(Generic,Generic1)importText.Read(Read(..),readListDefault,readListPrecDefault)infixr9`Compose`-- | Right-to-left composition of functors.-- The composition of applicative functors is always applicative,-- but the composition of monads is not always a monad.newtypeComposefga=Compose{getCompose::f(ga)}deriving(Data-- ^ @since 4.9.0.0,Generic-- ^ @since 4.9.0.0,Generic1-- ^ @since 4.9.0.0)-- Instances of lifted Prelude classes-- | @since 4.9.0.0instance(Eq1f,Eq1g)=>Eq1(Composefg)whereliftEqeq(Composex)(Composey)=liftEq(liftEqeq)xy-- | @since 4.9.0.0instance(Ord1f,Ord1g)=>Ord1(Composefg)whereliftComparecomp(Composex)(Composey)=liftCompare(liftComparecomp)xy-- | @since 4.9.0.0instance(Read1f,Read1g)=>Read1(Composefg)whereliftReadPrecrprl=readData$readUnaryWith(liftReadPrecrp'rl')"Compose"Composewhererp'=liftReadPrecrprlrl'=liftReadListPrecrprlliftReadListPrec=liftReadListPrecDefaultliftReadList=liftReadListDefault-- | @since 4.9.0.0instance(Show1f,Show1g)=>Show1(Composefg)whereliftShowsPrecspsld(Composex)=showsUnaryWith(liftShowsPrecsp'sl')"Compose"dxwheresp'=liftShowsPrecspslsl'=liftShowListspsl-- Instances of Prelude classes-- | @since 4.9.0.0instance(Eq1f,Eq1g,Eqa)=>Eq(Composefga)where(==)=eq1-- | @since 4.9.0.0instance(Ord1f,Ord1g,Orda)=>Ord(Composefga)wherecompare=compare1-- | @since 4.9.0.0instance(Read1f,Read1g,Reada)=>Read(Composefga)wherereadPrec=readPrec1readListPrec=readListPrecDefaultreadList=readListDefault-- | @since 4.9.0.0instance(Show1f,Show1g,Showa)=>Show(Composefga)whereshowsPrec=showsPrec1-- Functor instances-- | @since 4.9.0.0instance(Functorf,Functorg)=>Functor(Composefg)wherefmapf(Composex)=Compose(fmap(fmapf)x)-- | @since 4.9.0.0instance(Foldablef,Foldableg)=>Foldable(Composefg)wherefoldMapf(Composet)=foldMap(foldMapf)t-- | @since 4.9.0.0instance(Traversablef,Traversableg)=>Traversable(Composefg)wheretraversef(Composet)=Compose<$>traverse(traversef)t-- | @since 4.9.0.0instance(Applicativef,Applicativeg)=>Applicative(Composefg)wherepurex=Compose(pure(purex))Composef<*>Composex=Compose(liftA2(<*>)fx)liftA2f(Composex)(Composey)=Compose(liftA2(liftA2f)xy)-- | @since 4.9.0.0instance(Alternativef,Applicativeg)=>Alternative(Composefg)whereempty=Composeempty(<|>)=coerce((<|>)::f(ga)->f(ga)->f(ga))::foralla.Composefga->Composefga->Composefga
[8]ページ先頭