Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP, Rank2Types, ScopedTypeVariables #-}------------------------------------------------------------------------------- |-- Module      :  Data.Data-- Copyright   :  (c) The University of Glasgow, CWI 2001--2004-- License     :  BSD-style (see the file libraries/base/LICENSE)---- Maintainer  :  libraries@haskell.org-- Stability   :  experimental-- Portability :  non-portable (local universal quantification)---- \"Scrap your boilerplate\" --- Generic programming in Haskell.-- See <http://www.cs.vu.nl/boilerplate/>. This module provides-- the 'Data' class with its primitives for generic programming, along-- with instances for many datatypes. It corresponds to a merge between-- the previous "Data.Generics.Basics" and almost all of-- "Data.Generics.Instances". The instances that are not present-- in this module were moved to the @Data.Generics.Instances@ module-- in the @syb@ package.---- For more information, please visit the new-- SYB wiki: <http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB>.---------------------------------------------------------------------------------moduleData.Data(-- * Module Data.Typeable re-exported for conveniencemoduleData.Typeable,-- * The Data class for processing constructor applicationsData(gfoldl,-- :: ... -> a -> c agunfold,-- :: ... -> Constr -> c atoConstr,-- :: a -> ConstrdataTypeOf,-- :: a -> DataTypedataCast1,-- mediate types and unary type constructorsdataCast2,-- mediate types and binary type constructors-- Generic maps defined in terms of gfoldlgmapT,gmapQ,gmapQl,gmapQr,gmapQi,gmapM,gmapMp,gmapMo),-- * Datatype representationsDataType,-- abstract, instance of: Show-- ** ConstructorsmkDataType,-- :: String   -> [Constr] -> DataTypemkIntType,-- :: String -> DataTypemkFloatType,-- :: String -> DataTypemkStringType,-- :: String -> DataTypemkCharType,-- :: String -> DataTypemkNoRepType,-- :: String -> DataTypemkNorepType,-- :: String -> DataType-- ** ObserversdataTypeName,-- :: DataType -> StringDataRep(..),-- instance of: Eq, ShowdataTypeRep,-- :: DataType -> DataRep-- ** Convenience functionsrepConstr,-- :: DataType -> ConstrRep -> ConstrisAlgType,-- :: DataType -> BooldataTypeConstrs,-- :: DataType -> [Constr]indexConstr,-- :: DataType -> ConIndex -> ConstrmaxConstrIndex,-- :: DataType -> ConIndexisNorepType,-- :: DataType -> Bool-- * Data constructor representationsConstr,-- abstract, instance of: Eq, ShowConIndex,-- alias for Int, start at 1Fixity(..),-- instance of: Eq, Show-- ** ConstructorsmkConstr,-- :: DataType -> String -> Fixity -> ConstrmkIntConstr,-- :: DataType -> Integer -> ConstrmkFloatConstr,-- :: DataType -> Double -> ConstrmkIntegralConstr,-- :: (Integral a) => DataType -> a -> ConstrmkRealConstr,-- :: (Real a) => DataType -> a -> ConstrmkStringConstr,-- :: DataType -> String  -> ConstrmkCharConstr,-- :: DataType -> Char -> Constr-- ** ObserversconstrType,-- :: Constr   -> DataTypeConstrRep(..),-- instance of: Eq, ShowconstrRep,-- :: Constr   -> ConstrRepconstrFields,-- :: Constr   -> [String]constrFixity,-- :: Constr   -> Fixity-- ** Convenience function: algebraic data typesconstrIndex,-- :: Constr   -> ConIndex-- ** From strings to constructors and vice versa: all data typesshowConstr,-- :: Constr   -> StringreadConstr,-- :: DataType -> String -> Maybe Constr-- * Convenience functions: take type constructors aparttyconUQname,-- :: String -> StringtyconModule,-- :: String -> String-- * Generic operations defined in terms of 'gunfold'fromConstr,-- :: Constr -> afromConstrB,-- :: ... -> Constr -> afromConstrM-- :: Monad m => ... -> Constr -> m a)where------------------------------------------------------------------------------importPrelude-- necessary to get dependencies rightimportData.TypeableimportData.MaybeimportControl.Monad-- Imports for the instancesimportData.Int-- So we can give Data instance for Int8, ...importData.Word-- So we can give Data instance for Word8, ...#ifdef __GLASGOW_HASKELL__importGHC.Real(Ratio(..))-- So we can give Data instance for Ratio--import GHC.IOBase            -- So we can give Data instance for IO, HandleimportGHC.Ptr-- So we can give Data instance for PtrimportGHC.ForeignPtr-- So we can give Data instance for ForeignPtr--import GHC.Stable            -- So we can give Data instance for StablePtr--import GHC.ST                -- So we can give Data instance for ST--import GHC.Conc              -- So we can give Data instance for MVar & Co.importGHC.Arr-- So we can give Data instance for Array#else# ifdef __HUGS__importHugs.Prelude(Ratio(..))# endifimportForeign.PtrimportForeign.ForeignPtrimportData.Array#endif#include "Typeable.h"----------------------------------------------------------------------------------      The Data class--------------------------------------------------------------------------------{- |The 'Data' class comprehends a fundamental primitive 'gfoldl' forfolding over constructor applications, say terms. This primitive canbe instantiated in several ways to map over the immediate subtermsof a term; see the @gmap@ combinators later in this class.  Indeed, ageneric programmer does not necessarily need to use the ingenious gfoldlprimitive but rather the intuitive @gmap@ combinators.  The 'gfoldl'primitive is completed by means to query top-level constructors, toturn constructor representations into proper terms, and to list allpossible datatype constructors.  This completion allows us to servegeneric programming scenarios like read, show, equality, term generation.The combinators 'gmapT', 'gmapQ', 'gmapM', etc are all provided withdefault definitions in terms of 'gfoldl', leaving open the opportunityto provide datatype-specific definitions.(The inclusion of the @gmap@ combinators as members of class 'Data'allows the programmer or the compiler to derive specialised, and maybemore efficient code per datatype.  /Note/: 'gfoldl' is more higher-orderthan the @gmap@ combinators.  This is subject to ongoing benchmarkingexperiments.  It might turn out that the @gmap@ combinators will bemoved out of the class 'Data'.)Conceptually, the definition of the @gmap@ combinators in terms of theprimitive 'gfoldl' requires the identification of the 'gfoldl' functionarguments.  Technically, we also need to identify the type constructor@c@ for the construction of the result type from the folded term type.In the definition of @gmapQ@/x/ combinators, we use phantom typeconstructors for the @c@ in the type of 'gfoldl' because the result typeof a query does not involve the (polymorphic) type of the term argument.In the definition of 'gmapQl' we simply use the plain constant typeconstructor because 'gfoldl' is left-associative anyway and so it isreadily suited to fold a left-associative binary operation over theimmediate subterms.  In the definition of gmapQr, extra effort isneeded. We use a higher-order accumulation trick to mediate betweenleft-associative constructor application vs. right-associative binaryoperation (e.g., @(:)@).  When the query is meant to compute a valueof type @r@, then the result type withing generic folding is @r -> r@.So the result of folding is a function to which we finally pass theright unit.With the @-XDeriveDataTypeable@ option, GHC can generate instances of the'Data' class automatically.  For example, given the declaration> data T a b = C1 a b | C2 deriving (Typeable, Data)GHC will generate an instance that is equivalent to> instance (Data a, Data b) => Data (T a b) where>     gfoldl k z (C1 a b) = z C1 `k` a `k` b>     gfoldl k z C2       = z C2>>     gunfold k z c = case constrIndex c of>                         1 -> k (k (z C1))>                         2 -> z C2>>     toConstr (C1 _ _) = con_C1>     toConstr C2       = con_C2>>     dataTypeOf _ = ty_T>> con_C1 = mkConstr ty_T "C1" [] Prefix> con_C2 = mkConstr ty_T "C2" [] Prefix> ty_T   = mkDataType "Module.T" [con_C1, con_C2]This is suitable for datatypes that are exported transparently.-}classTypeablea=>Dataawhere-- | Left-associative fold operation for constructor applications.---- The type of 'gfoldl' is a headache, but operationally it is a simple-- generalisation of a list fold.---- The default definition for 'gfoldl' is @'const' 'id'@, which is-- suitable for abstract datatypes with no substructures.gfoldl::(foralldb.Datad=>c(d->b)->d->cb)-- ^ defines how nonempty constructor applications are-- folded.  It takes the folded tail of the constructor-- application and its head, i.e., an immediate subterm,-- and combines them in some way.->(forallg.g->cg)-- ^ defines how the empty constructor application is-- folded, like the neutral \/ start element for list-- folding.->a-- ^ structure to be folded.->ca-- ^ result, with a type defined in terms of @a@, but-- variability is achieved by means of type constructor-- @c@ for the construction of the actual result type.-- See the 'Data' instances in this file for an illustration of 'gfoldl'.gfoldl_z=z-- | Unfolding constructor applicationsgunfold::(forallbr.Datab=>c(b->r)->cr)->(forallr.r->cr)->Constr->ca-- | Obtaining the constructor from a given datum.-- For proper terms, this is meant to be the top-level constructor.-- Primitive datatypes are here viewed as potentially infinite sets of-- values (i.e., constructors).toConstr::a->Constr-- | The outer type constructor of the typedataTypeOf::a->DataType---------------------------------------------------------------------------------- Mediate types and type constructors---------------------------------------------------------------------------------- | Mediate types and unary type constructors.-- In 'Data' instances of the form @T a@, 'dataCast1' should be defined-- as 'gcast1'.---- The default definition is @'const' 'Nothing'@, which is appropriate-- for non-unary type constructors.dataCast1::Typeable1t=>(foralld.Datad=>c(td))->Maybe(ca)dataCast1_=Nothing-- | Mediate types and binary type constructors.-- In 'Data' instances of the form @T a b@, 'dataCast2' should be-- defined as 'gcast2'.---- The default definition is @'const' 'Nothing'@, which is appropriate-- for non-binary type constructors.dataCast2::Typeable2t=>(forallde.(Datad,Datae)=>c(tde))->Maybe(ca)dataCast2_=Nothing----------------------------------------------------------------------------------      Typical generic maps defined in terms of gfoldl---------------------------------------------------------------------------------- | A generic transformation that maps over the immediate subterms---- The default definition instantiates the type constructor @c@ in the-- type of 'gfoldl' to an identity datatype constructor, using the-- isomorphism pair as injection and projection.gmapT::(forallb.Datab=>b->b)->a->a-- Use an identity datatype constructor ID (see below)-- to instantiate the type constructor c in the type of gfoldl,-- and perform injections ID and projections unID accordingly.--gmapTfx0=unID(gfoldlkIDx0)wherek::Datad=>ID(d->b)->d->IDbk(IDc)x=ID(c(fx))-- | A generic query with a left-associative binary operatorgmapQl::forallrr'.(r->r'->r)->r->(foralld.Datad=>d->r')->a->rgmapQlorf=unCONST.gfoldlkzwherek::Datad=>CONSTr(d->b)->d->CONSTrbkcx=CONST$(unCONSTc)`o`fxz::g->CONSTrgz_=CONSTr-- | A generic query with a right-associative binary operatorgmapQr::forallrr'.(r'->r->r)->r->(foralld.Datad=>d->r')->a->rgmapQror0fx0=unQr(gfoldlk(const(Qrid))x0)r0wherek::Datad=>Qrr(d->b)->d->Qrrbk(Qrc)x=Qr(\r->c(fx`o`r))-- | A generic query that processes the immediate subterms and returns a list-- of results.  The list is given in the same order as originally specified-- in the declaratoin of the data constructors.gmapQ::(foralld.Datad=>d->u)->a->[u]gmapQf=gmapQr(:)[]f-- | A generic query that processes one child by index (zero-based)gmapQi::forallu.Int->(foralld.Datad=>d->u)->a->ugmapQiifx=casegfoldlkzxof{Qi_q->fromJustq}wherek::Datad=>Qiu(d->b)->d->Qiubk(Qii'q)a=Qi(i'+1)(ifi==i'thenJust(fa)elseq)z::g->Qiqgz_=Qi0Nothing-- | A generic monadic transformation that maps over the immediate subterms---- The default definition instantiates the type constructor @c@ in-- the type of 'gfoldl' to the monad datatype constructor, defining-- injection and projection using 'return' and '>>='.gmapM::forallm.Monadm=>(foralld.Datad=>d->md)->a->ma-- Use immediately the monad datatype constructor-- to instantiate the type constructor c in the type of gfoldl,-- so injection and projection is done by return and >>=.--gmapMf=gfoldlkreturnwherek::Datad=>m(d->b)->d->mbkcx=doc'<-cx'<-fxreturn(c'x')-- | Transformation of at least one immediate subterm does not failgmapMp::forallm.MonadPlusm=>(foralld.Datad=>d->md)->a->ma{-The type constructor that we use here simply keeps track of the factif we already succeeded for an immediate subterm; see Mp below. Tothis end, we couple the monadic computation with a Boolean.-}gmapMpfx=unMp(gfoldlkzx)>>=\(x',b)->ifbthenreturnx'elsemzerowherez::g->Mpmgzg=Mp(return(g,False))k::Datad=>Mpm(d->b)->d->Mpmbk(Mpc)y=Mp(c>>=\(h,b)->(fy>>=\y'->return(hy',True))`mplus`return(hy,b))-- | Transformation of one immediate subterm with successgmapMo::forallm.MonadPlusm=>(foralld.Datad=>d->md)->a->ma{-We use the same pairing trick as for gmapMp,i.e., we use an extra Bool component to keep track of thefact whether an immediate subterm was processed successfully.However, we cut of mapping over subterms once a first subtermwas transformed successfully.-}gmapMofx=unMp(gfoldlkzx)>>=\(x',b)->ifbthenreturnx'elsemzerowherez::g->Mpmgzg=Mp(return(g,False))k::Datad=>Mpm(d->b)->d->Mpmbk(Mpc)y=Mp(c>>=\(h,b)->ifbthenreturn(hy,b)else(fy>>=\y'->return(hy',True))`mplus`return(hy,b))-- | The identity type constructor needed for the definition of gmapTnewtypeIDx=ID{unID::x}-- | The constant type constructor needed for the definition of gmapQlnewtypeCONSTca=CONST{unCONST::c}-- | Type constructor for adding counters to queriesdataQiqa=QiInt(Maybeq)-- | The type constructor used in definition of gmapQrnewtypeQrra=Qr{unQr::r->r}-- | The type constructor used in definition of gmapMpnewtypeMpmx=Mp{unMp::m(x,Bool)}----------------------------------------------------------------------------------      Generic unfolding---------------------------------------------------------------------------------- | Build a term skeletonfromConstr::Dataa=>Constr->afromConstr=fromConstrB(error"Data.Data.fromConstr")-- | Build a term and use a generic function for subtermsfromConstrB::Dataa=>(foralld.Datad=>d)->Constr->afromConstrBf=unID.gunfoldkzwherek::forallbr.Datab=>ID(b->r)->IDrkc=ID(unIDcf)z::forallr.r->IDrz=ID-- | Monadic variation on 'fromConstrB'fromConstrM::forallma.(Monadm,Dataa)=>(foralld.Datad=>md)->Constr->mafromConstrMf=gunfoldkzwherek::forallbr.Datab=>m(b->r)->mrkc=do{c'<-c;b<-f;return(c'b)}z::forallr.r->mrz=return----------------------------------------------------------------------------------      Datatype and constructor representations------------------------------------------------------------------------------------ | Representation of datatypes.-- A package of constructor representations with names of type and module.--dataDataType=DataType{tycon::String,datarep::DataRep}derivingShow-- | Representation of constructors. Note that equality on constructors-- with different types may not work -- i.e. the constructors for 'False' and-- 'Nothing' may compare equal.dataConstr=Constr{conrep::ConstrRep,constring::String,confields::[String]-- for AlgRep only,confixity::Fixity-- for AlgRep only,datatype::DataType}instanceShowConstrwhereshow=constring-- | Equality of constructorsinstanceEqConstrwherec==c'=constrRepc==constrRepc'-- | Public representation of datatypesdataDataRep=AlgRep[Constr]|IntRep|FloatRep|CharRep|NoRepderiving(Eq,Show)-- The list of constructors could be an array, a balanced tree, or others.-- | Public representation of constructorsdataConstrRep=AlgConstrConIndex|IntConstrInteger|FloatConstrRational|CharConstrCharderiving(Eq,Show)-- | Unique index for datatype constructors,-- counting from 1 in the order they are given in the program text.typeConIndex=Int-- | Fixity of constructorsdataFixity=Prefix|Infix-- Later: add associativity and precedencederiving(Eq,Show)----------------------------------------------------------------------------------      Observers for datatype representations---------------------------------------------------------------------------------- | Gets the type constructor including the moduledataTypeName::DataType->StringdataTypeName=tycon-- | Gets the public presentation of a datatypedataTypeRep::DataType->DataRepdataTypeRep=datarep-- | Gets the datatype of a constructorconstrType::Constr->DataTypeconstrType=datatype-- | Gets the public presentation of constructorsconstrRep::Constr->ConstrRepconstrRep=conrep-- | Look up a constructor by its representationrepConstr::DataType->ConstrRep->ConstrrepConstrdtcr=case(dataTypeRepdt,cr)of(AlgRepcs,AlgConstri)->cs!!(i-1)(IntRep,IntConstri)->mkIntConstrdti(FloatRep,FloatConstrf)->mkRealConstrdtf(CharRep,CharConstrc)->mkCharConstrdtc_->error"Data.Data.repConstr"----------------------------------------------------------------------------------      Representations of algebraic data types---------------------------------------------------------------------------------- | Constructs an algebraic datatypemkDataType::String->[Constr]->DataTypemkDataTypestrcs=DataType{tycon=str,datarep=AlgRepcs}-- | Constructs a constructormkConstr::DataType->String->[String]->Fixity->ConstrmkConstrdtstrfieldsfix=Constr{conrep=AlgConstridx,constring=str,confields=fields,confixity=fix,datatype=dt}whereidx=head[i|(c,i)<-dataTypeConstrsdt`zip`[1..],showConstrc==str]-- | Gets the constructors of an algebraic datatypedataTypeConstrs::DataType->[Constr]dataTypeConstrsdt=casedatarepdtof(AlgRepcons)->cons_->error"Data.Data.dataTypeConstrs"-- | Gets the field labels of a constructor.  The list of labels-- is returned in the same order as they were given in the original-- constructor declaration.constrFields::Constr->[String]constrFields=confields-- | Gets the fixity of a constructorconstrFixity::Constr->FixityconstrFixity=confixity----------------------------------------------------------------------------------      From strings to constr's and vice versa: all data types---------------------------------------------------------------------------------- | Gets the string for a constructorshowConstr::Constr->StringshowConstr=constring-- | Lookup a constructor via a stringreadConstr::DataType->String->MaybeConstrreadConstrdtstr=casedataTypeRepdtofAlgRepcons->idxconsIntRep->mkReadCon(\i->(mkPrimCondtstr(IntConstri)))FloatRep->mkReadConffloatCharRep->mkReadCon(\c->(mkPrimCondtstr(CharConstrc)))NoRep->Nothingwhere-- Read a value and build a constructormkReadCon::Readt=>(t->Constr)->MaybeConstrmkReadConf=case(readsstr)of[(t,"")]->Just(ft)_->Nothing-- Traverse list of algebraic datatype constructorsidx::[Constr]->MaybeConstridxcons=letfit=filter((==)str.showConstr)consiniffit==[]thenNothingelseJust(headfit)ffloat::Double->Constrffloat=mkPrimCondtstr.FloatConstr.toRational----------------------------------------------------------------------------------      Convenience funtions: algebraic data types---------------------------------------------------------------------------------- | Test for an algebraic typeisAlgType::DataType->BoolisAlgTypedt=casedatarepdtof(AlgRep_)->True_->False-- | Gets the constructor for an index (algebraic datatypes only)indexConstr::DataType->ConIndex->ConstrindexConstrdtidx=casedatarepdtof(AlgRepcs)->cs!!(idx-1)_->error"Data.Data.indexConstr"-- | Gets the index of a constructor (algebraic datatypes only)constrIndex::Constr->ConIndexconstrIndexcon=caseconstrRepconof(AlgConstridx)->idx_->error"Data.Data.constrIndex"-- | Gets the maximum constructor index of an algebraic datatypemaxConstrIndex::DataType->ConIndexmaxConstrIndexdt=casedataTypeRepdtofAlgRepcs->lengthcs_->error"Data.Data.maxConstrIndex"----------------------------------------------------------------------------------      Representation of primitive types---------------------------------------------------------------------------------- | Constructs the 'Int' typemkIntType::String->DataTypemkIntType=mkPrimTypeIntRep-- | Constructs the 'Float' typemkFloatType::String->DataTypemkFloatType=mkPrimTypeFloatRep-- | This function is now deprecated. Please use 'mkCharType' instead.{-# DEPRECATED mkStringType "Use mkCharType instead" #-}mkStringType::String->DataTypemkStringType=mkCharType-- | Constructs the 'Char' typemkCharType::String->DataTypemkCharType=mkPrimTypeCharRep-- | Helper for 'mkIntType', 'mkFloatType', 'mkStringType'mkPrimType::DataRep->String->DataTypemkPrimTypedrstr=DataType{tycon=str,datarep=dr}-- Makes a constructor for primitive typesmkPrimCon::DataType->String->ConstrRep->ConstrmkPrimCondtstrcr=Constr{datatype=dt,conrep=cr,constring=str,confields=error"Data.Data.confields",confixity=error"Data.Data.confixity"}-- | This function is now deprecated. Please use 'mkIntegralConstr' instead.{-# DEPRECATED mkIntConstr "Use mkIntegralConstr instead" #-}mkIntConstr::DataType->Integer->ConstrmkIntConstr=mkIntegralConstrmkIntegralConstr::(Integrala)=>DataType->a->ConstrmkIntegralConstrdti=casedatarepdtofIntRep->mkPrimCondt(showi)(IntConstr(toIntegeri))_->error"Data.Data.mkIntegralConstr"-- | This function is now deprecated. Please use 'mkRealConstr' instead.{-# DEPRECATED mkFloatConstr "Use mkRealConstr instead" #-}mkFloatConstr::DataType->Double->ConstrmkFloatConstrdt=mkRealConstrdt.toRationalmkRealConstr::(Reala)=>DataType->a->ConstrmkRealConstrdtf=casedatarepdtofFloatRep->mkPrimCondt(showf)(FloatConstr(toRationalf))_->error"Data.Data.mkRealConstr"-- | This function is now deprecated. Please use 'mkCharConstr' instead.{-# DEPRECATED mkStringConstr "Use mkCharConstr instead" #-}mkStringConstr::DataType->String->ConstrmkStringConstrdtstr=casedatarepdtofCharRep->casestrof[c]->mkPrimCondt(showc)(CharConstrc)_->error"Data.Data.mkStringConstr: input String must contain a single character"_->error"Data.Data.mkStringConstr"-- | Makes a constructor for 'Char'.mkCharConstr::DataType->Char->ConstrmkCharConstrdtc=casedatarepdtofCharRep->mkPrimCondt(showc)(CharConstrc)_->error"Data.Data.mkCharConstr"----------------------------------------------------------------------------------      Non-representations for non-presentable types---------------------------------------------------------------------------------- | Deprecated version (misnamed){-# DEPRECATED mkNorepType "Use mkNoRepType instead" #-}mkNorepType::String->DataTypemkNorepTypestr=DataType{tycon=str,datarep=NoRep}-- | Constructs a non-representation for a non-presentable typemkNoRepType::String->DataTypemkNoRepTypestr=DataType{tycon=str,datarep=NoRep}-- | Test for a non-representable typeisNorepType::DataType->BoolisNorepTypedt=casedatarepdtofNoRep->True_->False----------------------------------------------------------------------------------      Convenience for qualified type constructors---------------------------------------------------------------------------------- | Gets the unqualified type constructor:-- drop *.*.*... before name--tyconUQname::String->StringtyconUQnamex=letx'=dropWhile(not.(==)'.')xinifx'==[]thenxelsetyconUQname(tailx')-- | Gets the module of a type constructor:-- take *.*.*... before nametyconModule::String->StringtyconModulex=let(a,b)=break((==)'.')xinifb==""thenbelsea++tyconModule'(tailb)wheretyconModule'y=lety'=tyconModuleyinify'==""then""else('.':y')----------------------------------------------------------------------------------------------------------------------------------------------------------------      Instances of the Data class for Prelude-like types.--      We define top-level definitions for representations.--------------------------------------------------------------------------------falseConstr::ConstrfalseConstr=mkConstrboolDataType"False"[]PrefixtrueConstr::ConstrtrueConstr=mkConstrboolDataType"True"[]PrefixboolDataType::DataTypeboolDataType=mkDataType"Prelude.Bool"[falseConstr,trueConstr]instanceDataBoolwheretoConstrFalse=falseConstrtoConstrTrue=trueConstrgunfold_zc=caseconstrIndexcof1->zFalse2->zTrue_->error"Data.Data.gunfold(Bool)"dataTypeOf_=boolDataType------------------------------------------------------------------------------charType::DataTypecharType=mkCharType"Prelude.Char"instanceDataCharwheretoConstrx=mkCharConstrcharTypexgunfold_zc=caseconstrRepcof(CharConstrx)->zx_->error"Data.Data.gunfold(Char)"dataTypeOf_=charType------------------------------------------------------------------------------floatType::DataTypefloatType=mkFloatType"Prelude.Float"instanceDataFloatwheretoConstr=mkRealConstrfloatTypegunfold_zc=caseconstrRepcof(FloatConstrx)->z(realToFracx)_->error"Data.Data.gunfold(Float)"dataTypeOf_=floatType------------------------------------------------------------------------------doubleType::DataTypedoubleType=mkFloatType"Prelude.Double"instanceDataDoublewheretoConstr=mkRealConstrdoubleTypegunfold_zc=caseconstrRepcof(FloatConstrx)->z(realToFracx)_->error"Data.Data.gunfold(Double)"dataTypeOf_=doubleType------------------------------------------------------------------------------intType::DataTypeintType=mkIntType"Prelude.Int"instanceDataIntwheretoConstrx=mkIntConstrintType(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Int)"dataTypeOf_=intType------------------------------------------------------------------------------integerType::DataTypeintegerType=mkIntType"Prelude.Integer"instanceDataIntegerwheretoConstr=mkIntConstrintegerTypegunfold_zc=caseconstrRepcof(IntConstrx)->zx_->error"Data.Data.gunfold(Integer)"dataTypeOf_=integerType------------------------------------------------------------------------------int8Type::DataTypeint8Type=mkIntType"Data.Int.Int8"instanceDataInt8wheretoConstrx=mkIntConstrint8Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Int8)"dataTypeOf_=int8Type------------------------------------------------------------------------------int16Type::DataTypeint16Type=mkIntType"Data.Int.Int16"instanceDataInt16wheretoConstrx=mkIntConstrint16Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Int16)"dataTypeOf_=int16Type------------------------------------------------------------------------------int32Type::DataTypeint32Type=mkIntType"Data.Int.Int32"instanceDataInt32wheretoConstrx=mkIntConstrint32Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Int32)"dataTypeOf_=int32Type------------------------------------------------------------------------------int64Type::DataTypeint64Type=mkIntType"Data.Int.Int64"instanceDataInt64wheretoConstrx=mkIntConstrint64Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Int64)"dataTypeOf_=int64Type------------------------------------------------------------------------------wordType::DataTypewordType=mkIntType"Data.Word.Word"instanceDataWordwheretoConstrx=mkIntConstrwordType(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Word)"dataTypeOf_=wordType------------------------------------------------------------------------------word8Type::DataTypeword8Type=mkIntType"Data.Word.Word8"instanceDataWord8wheretoConstrx=mkIntConstrword8Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Word8)"dataTypeOf_=word8Type------------------------------------------------------------------------------word16Type::DataTypeword16Type=mkIntType"Data.Word.Word16"instanceDataWord16wheretoConstrx=mkIntConstrword16Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Word16)"dataTypeOf_=word16Type------------------------------------------------------------------------------word32Type::DataTypeword32Type=mkIntType"Data.Word.Word32"instanceDataWord32wheretoConstrx=mkIntConstrword32Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Word32)"dataTypeOf_=word32Type------------------------------------------------------------------------------word64Type::DataTypeword64Type=mkIntType"Data.Word.Word64"instanceDataWord64wheretoConstrx=mkIntConstrword64Type(fromIntegralx)gunfold_zc=caseconstrRepcof(IntConstrx)->z(fromIntegralx)_->error"Data.Data.gunfold(Word64)"dataTypeOf_=word64Type------------------------------------------------------------------------------ratioConstr::ConstrratioConstr=mkConstrratioDataType":%"[]InfixratioDataType::DataTyperatioDataType=mkDataType"GHC.Real.Ratio"[ratioConstr]instance(Dataa,Integrala)=>Data(Ratioa)wheregfoldlkz(a:%b)=z(:%)`k`a`k`btoConstr_=ratioConstrgunfoldkzc|constrIndexc==1=k(k(z(:%)))gunfold___=error"Data.Data.gunfold(Ratio)"dataTypeOf_=ratioDataType------------------------------------------------------------------------------nilConstr::ConstrnilConstr=mkConstrlistDataType"[]"[]PrefixconsConstr::ConstrconsConstr=mkConstrlistDataType"(:)"[]InfixlistDataType::DataTypelistDataType=mkDataType"Prelude.[]"[nilConstr,consConstr]instanceDataa=>Data[a]wheregfoldl_z[]=z[]gfoldlfz(x:xs)=z(:)`f`x`f`xstoConstr[]=nilConstrtoConstr(_:_)=consConstrgunfoldkzc=caseconstrIndexcof1->z[]2->k(k(z(:)))_->error"Data.Data.gunfold(List)"dataTypeOf_=listDataTypedataCast1f=gcast1f---- The gmaps are given as an illustration.-- This shows that the gmaps for lists are different from list maps.--gmapT_[]=[]gmapTf(x:xs)=(fx:fxs)gmapQ_[]=[]gmapQf(x:xs)=[fx,fxs]gmapM_[]=return[]gmapMf(x:xs)=fx>>=\x'->fxs>>=\xs'->return(x':xs')------------------------------------------------------------------------------nothingConstr::ConstrnothingConstr=mkConstrmaybeDataType"Nothing"[]PrefixjustConstr::ConstrjustConstr=mkConstrmaybeDataType"Just"[]PrefixmaybeDataType::DataTypemaybeDataType=mkDataType"Prelude.Maybe"[nothingConstr,justConstr]instanceDataa=>Data(Maybea)wheregfoldl_zNothing=zNothinggfoldlfz(Justx)=zJust`f`xtoConstrNothing=nothingConstrtoConstr(Just_)=justConstrgunfoldkzc=caseconstrIndexcof1->zNothing2->k(zJust)_->error"Data.Data.gunfold(Maybe)"dataTypeOf_=maybeDataTypedataCast1f=gcast1f------------------------------------------------------------------------------ltConstr::ConstrltConstr=mkConstrorderingDataType"LT"[]PrefixeqConstr::ConstreqConstr=mkConstrorderingDataType"EQ"[]PrefixgtConstr::ConstrgtConstr=mkConstrorderingDataType"GT"[]PrefixorderingDataType::DataTypeorderingDataType=mkDataType"Prelude.Ordering"[ltConstr,eqConstr,gtConstr]instanceDataOrderingwheregfoldl_zLT=zLTgfoldl_zEQ=zEQgfoldl_zGT=zGTtoConstrLT=ltConstrtoConstrEQ=eqConstrtoConstrGT=gtConstrgunfold_zc=caseconstrIndexcof1->zLT2->zEQ3->zGT_->error"Data.Data.gunfold(Ordering)"dataTypeOf_=orderingDataType------------------------------------------------------------------------------leftConstr::ConstrleftConstr=mkConstreitherDataType"Left"[]PrefixrightConstr::ConstrrightConstr=mkConstreitherDataType"Right"[]PrefixeitherDataType::DataTypeeitherDataType=mkDataType"Prelude.Either"[leftConstr,rightConstr]instance(Dataa,Datab)=>Data(Eitherab)wheregfoldlfz(Lefta)=zLeft`f`agfoldlfz(Righta)=zRight`f`atoConstr(Left_)=leftConstrtoConstr(Right_)=rightConstrgunfoldkzc=caseconstrIndexcof1->k(zLeft)2->k(zRight)_->error"Data.Data.gunfold(Either)"dataTypeOf_=eitherDataTypedataCast2f=gcast2f------------------------------------------------------------------------------tuple0Constr::Constrtuple0Constr=mkConstrtuple0DataType"()"[]Prefixtuple0DataType::DataTypetuple0DataType=mkDataType"Prelude.()"[tuple0Constr]instanceData()wheretoConstr()=tuple0Constrgunfold_zc|constrIndexc==1=z()gunfold___=error"Data.Data.gunfold(unit)"dataTypeOf_=tuple0DataType------------------------------------------------------------------------------tuple2Constr::Constrtuple2Constr=mkConstrtuple2DataType"(,)"[]Infixtuple2DataType::DataTypetuple2DataType=mkDataType"Prelude.(,)"[tuple2Constr]instance(Dataa,Datab)=>Data(a,b)wheregfoldlfz(a,b)=z(,)`f`a`f`btoConstr(_,_)=tuple2Constrgunfoldkzc|constrIndexc==1=k(k(z(,)))gunfold___=error"Data.Data.gunfold(tup2)"dataTypeOf_=tuple2DataTypedataCast2f=gcast2f------------------------------------------------------------------------------tuple3Constr::Constrtuple3Constr=mkConstrtuple3DataType"(,,)"[]Infixtuple3DataType::DataTypetuple3DataType=mkDataType"Prelude.(,,)"[tuple3Constr]instance(Dataa,Datab,Datac)=>Data(a,b,c)wheregfoldlfz(a,b,c)=z(,,)`f`a`f`b`f`ctoConstr(_,_,_)=tuple3Constrgunfoldkzc|constrIndexc==1=k(k(k(z(,,))))gunfold___=error"Data.Data.gunfold(tup3)"dataTypeOf_=tuple3DataType------------------------------------------------------------------------------tuple4Constr::Constrtuple4Constr=mkConstrtuple4DataType"(,,,)"[]Infixtuple4DataType::DataTypetuple4DataType=mkDataType"Prelude.(,,,)"[tuple4Constr]instance(Dataa,Datab,Datac,Datad)=>Data(a,b,c,d)wheregfoldlfz(a,b,c,d)=z(,,,)`f`a`f`b`f`c`f`dtoConstr(_,_,_,_)=tuple4Constrgunfoldkzc=caseconstrIndexcof1->k(k(k(k(z(,,,)))))_->error"Data.Data.gunfold(tup4)"dataTypeOf_=tuple4DataType------------------------------------------------------------------------------tuple5Constr::Constrtuple5Constr=mkConstrtuple5DataType"(,,,,)"[]Infixtuple5DataType::DataTypetuple5DataType=mkDataType"Prelude.(,,,,)"[tuple5Constr]instance(Dataa,Datab,Datac,Datad,Datae)=>Data(a,b,c,d,e)wheregfoldlfz(a,b,c,d,e)=z(,,,,)`f`a`f`b`f`c`f`d`f`etoConstr(_,_,_,_,_)=tuple5Constrgunfoldkzc=caseconstrIndexcof1->k(k(k(k(k(z(,,,,))))))_->error"Data.Data.gunfold(tup5)"dataTypeOf_=tuple5DataType------------------------------------------------------------------------------tuple6Constr::Constrtuple6Constr=mkConstrtuple6DataType"(,,,,,)"[]Infixtuple6DataType::DataTypetuple6DataType=mkDataType"Prelude.(,,,,,)"[tuple6Constr]instance(Dataa,Datab,Datac,Datad,Datae,Dataf)=>Data(a,b,c,d,e,f)wheregfoldlfz(a,b,c,d,e,f')=z(,,,,,)`f`a`f`b`f`c`f`d`f`e`f`f'toConstr(_,_,_,_,_,_)=tuple6Constrgunfoldkzc=caseconstrIndexcof1->k(k(k(k(k(k(z(,,,,,)))))))_->error"Data.Data.gunfold(tup6)"dataTypeOf_=tuple6DataType------------------------------------------------------------------------------tuple7Constr::Constrtuple7Constr=mkConstrtuple7DataType"(,,,,,,)"[]Infixtuple7DataType::DataTypetuple7DataType=mkDataType"Prelude.(,,,,,,)"[tuple7Constr]instance(Dataa,Datab,Datac,Datad,Datae,Dataf,Datag)=>Data(a,b,c,d,e,f,g)wheregfoldlfz(a,b,c,d,e,f',g)=z(,,,,,,)`f`a`f`b`f`c`f`d`f`e`f`f'`f`gtoConstr(_,_,_,_,_,_,_)=tuple7Constrgunfoldkzc=caseconstrIndexcof1->k(k(k(k(k(k(k(z(,,,,,,))))))))_->error"Data.Data.gunfold(tup7)"dataTypeOf_=tuple7DataType------------------------------------------------------------------------------instanceTypeablea=>Data(Ptra)wheretoConstr_=error"Data.Data.toConstr(Ptr)"gunfold__=error"Data.Data.gunfold(Ptr)"dataTypeOf_=mkNoRepType"GHC.Ptr.Ptr"------------------------------------------------------------------------------instanceTypeablea=>Data(ForeignPtra)wheretoConstr_=error"Data.Data.toConstr(ForeignPtr)"gunfold__=error"Data.Data.gunfold(ForeignPtr)"dataTypeOf_=mkNoRepType"GHC.ForeignPtr.ForeignPtr"-------------------------------------------------------------------------------- The Data instance for Array preserves data abstraction at the cost of-- inefficiency. We omit reflection services for the sake of data abstraction.instance(Typeablea,Datab,Ixa)=>Data(Arrayab)wheregfoldlfza=z(listArray(boundsa))`f`(elemsa)toConstr_=error"Data.Data.toConstr(Array)"gunfold__=error"Data.Data.gunfold(Array)"dataTypeOf_=mkNoRepType"Data.Array.Array"

[8]ページ先頭

©2009-2025 Movatter.jp