Movatterモバイル変換
[0]ホーム
{-# LANGUAGE DeriveDataTypeable #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE DeriveTraversable #-}{-# LANGUAGE GeneralizedNewtypeDeriving #-}{-# LANGUAGE NoImplicitPrelude #-}{-# LANGUAGE Trustworthy #-}------------------------------------------------------------------------------- |-- Module : Data.Functor.Identity-- Copyright : (c) Andy Gill 2001,-- (c) Oregon Graduate Institute of Science and Technology 2001-- License : BSD-style (see the file LICENSE)---- Maintainer : ross@soi.city.ac.uk-- Stability : experimental-- Portability : portable---- The identity functor and monad.---- This trivial type constructor serves two purposes:---- * It can be used with functions parameterized by functor or monad classes.---- * It can be used as a base monad to which a series of monad-- transformers may be applied to construct a composite monad.-- Most monad transformer modules include the special case of-- applying the transformer to 'Identity'. For example, @State s@-- is an abbreviation for @StateT s 'Identity'@.---- @since 4.8.0.0-----------------------------------------------------------------------------moduleData.Functor.Identity(Identity(..),)whereimportControl.Monad.FiximportData.Bits(Bits,FiniteBits)importData.CoerceimportData.FoldableimportData.Functor.Utils((#.))importForeign.Storable(Storable)importGHC.Arr(Ix)importGHC.Base(Applicative(..),Eq(..),Functor(..),Monad(..),Semigroup,Monoid,Ord(..),($),(.))importGHC.Enum(Bounded,Enum)importGHC.Float(Floating,RealFloat)importGHC.Generics(Generic,Generic1)importGHC.Num(Num)importGHC.Read(Read(..),lex,readParen)importGHC.Real(Fractional,Integral,Real,RealFrac)importGHC.Show(Show(..),showParen,showString)importGHC.Types(Bool(..))-- | Identity functor and monad. (a non-strict monad)---- @since 4.8.0.0newtypeIdentitya=Identity{runIdentity::a}deriving(Bits-- ^ @since 4.9.0.0,Bounded-- ^ @since 4.9.0.0,Enum-- ^ @since 4.9.0.0,Eq-- ^ @since 4.8.0.0,FiniteBits-- ^ @since 4.9.0.0,Floating-- ^ @since 4.9.0.0,Fractional-- ^ @since 4.9.0.0,Generic-- ^ @since 4.8.0.0,Generic1-- ^ @since 4.8.0.0,Integral-- ^ @since 4.9.0.0,Ix-- ^ @since 4.9.0.0,Semigroup-- ^ @since 4.9.0.0,Monoid-- ^ @since 4.9.0.0,Num-- ^ @since 4.9.0.0,Ord-- ^ @since 4.8.0.0,Real-- ^ @since 4.9.0.0,RealFrac-- ^ @since 4.9.0.0,RealFloat-- ^ @since 4.9.0.0,Storable-- ^ @since 4.9.0.0)-- | This instance would be equivalent to the derived instances of the-- 'Identity' newtype if the 'runIdentity' field were removed---- @since 4.8.0.0instance(Reada)=>Read(Identitya)wherereadsPrecd=readParen(d>10)$\r->[(Identityx,t)|("Identity",s)<-lexr,(x,t)<-readsPrec11s]-- | This instance would be equivalent to the derived instances of the-- 'Identity' newtype if the 'runIdentity' field were removed---- @since 4.8.0.0instance(Showa)=>Show(Identitya)whereshowsPrecd(Identityx)=showParen(d>10)$showString"Identity ".showsPrec11x-- ----------------------------------------------------------------------------- Identity instances for Functor and Monad-- | @since 4.8.0.0instanceFoldableIdentitywherefoldMap=coerceelem=(.runIdentity)#.(==)foldl=coercefoldl'=coercefoldl1_=runIdentityfoldrfz(Identityx)=fxzfoldr'=foldrfoldr1_=runIdentitylength_=1maximum=runIdentityminimum=runIdentitynull_=Falseproduct=runIdentitysum=runIdentitytoList(Identityx)=[x]-- | @since 4.8.0.0instanceFunctorIdentitywherefmap=coerce-- | @since 4.8.0.0instanceApplicativeIdentitywherepure=Identity(<*>)=coerceliftA2=coerce-- | @since 4.8.0.0instanceMonadIdentitywherem>>=k=k(runIdentitym)-- | @since 4.8.0.0instanceMonadFixIdentitywheremfixf=Identity(fix(runIdentity.f))
[8]ページ先頭