Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE NoImplicitPrelude #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE PatternSynonyms #-}{-# LANGUAGE TypeOperators #-}------------------------------------------------------------------------------- |-- Module      :  Data.Typeable-- 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 :  portable---- The 'Typeable' class reifies types to some extent by associating type-- representations to types. These type representations can be compared,-- and one can in turn define a type-safe cast operation. To this end,-- an unsafe cast is guarded by a test for type (representation)-- equivalence. The module "Data.Dynamic" uses Typeable for an-- implementation of dynamics. The module "Data.Data" uses Typeable-- and type-safe cast (but not dynamics) to support the \"Scrap your-- boilerplate\" style of generic programming.---- == Compatibility Notes---- Since GHC 8.2, GHC has supported type-indexed type representations.-- "Data.Typeable" provides type representations which are qualified over this-- index, providing an interface very similar to the "Typeable" notion seen in-- previous releases. For the type-indexed interface, see "Type.Reflection".---- Since GHC 7.8, 'Typeable' is poly-kinded. The changes required for this might-- break some old programs involving 'Typeable'. More details on this, including-- how to fix your code, can be found on the-- <https://ghc.haskell.org/trac/ghc/wiki/GhcKinds/PolyTypeable PolyTypeable wiki page>-------------------------------------------------------------------------------moduleData.Typeable(-- * The Typeable classTypeable,typeOf,typeRep-- * Propositional equality,(:~:)(Refl),(:~~:)(HRefl)-- * Type-safe cast,cast,eqT,gcast-- a generalisation of cast-- * Generalized casts for higher-order kinds,gcast1-- :: ... => c (t a) -> Maybe (c (t' a)),gcast2-- :: ... => c (t a b) -> Maybe (c (t' a b))-- * A canonical proxy type,Proxy(..)-- * Type representations,TypeRep,rnfTypeRep,showsTypeRep,mkFunTy-- * Observing type representations,funResultTy,splitTyConApp,typeRepArgs,typeRepTyCon,typeRepFingerprint-- * Type constructors,I.TyCon-- abstract, instance of: Eq, Show, Typeable-- For now don't export Module to avoid name clashes,I.tyConPackage,I.tyConModule,I.tyConName,I.rnfTyCon,I.tyConFingerprint-- * For backwards compatibility,typeOf1,typeOf2,typeOf3,typeOf4,typeOf5,typeOf6,typeOf7)whereimportqualifiedData.Typeable.InternalasIimportData.Typeable.Internal(Typeable)importData.Type.EqualityimportData.MaybeimportData.ProxyimportGHC.Fingerprint.TypeimportGHC.ShowimportGHC.Base-- | A quantified type representation.typeTypeRep=I.SomeTypeRep-- | Observe a type representation for the type of a value.typeOf::foralla.Typeablea=>a->TypeReptypeOf_=I.someTypeRep(Proxy::Proxya)-- | Takes a value of type @a@ and returns a concrete representation-- of that type.---- @since 4.7.0.0typeRep::forallproxya.Typeablea=>proxya->TypeReptypeRep=I.someTypeRep-- | Show a type representationshowsTypeRep::TypeRep->ShowSshowsTypeRep=shows-- | The type-safe cast operationcast::forallab.(Typeablea,Typeableb)=>a->Maybebcastx|JustHRefl<-ta`I.eqTypeRep`tb=Justx|otherwise=Nothingwhereta=I.typeRep::I.TypeRepatb=I.typeRep::I.TypeRepb-- | Extract a witness of equality of two types---- @since 4.7.0.0eqT::forallab.(Typeablea,Typeableb)=>Maybe(a:~:b)eqT|JustHRefl<-ta`I.eqTypeRep`tb=JustRefl|otherwise=Nothingwhereta=I.typeRep::I.TypeRepatb=I.typeRep::I.TypeRepb-- | A flexible variation parameterised in a type constructorgcast::forallabc.(Typeablea,Typeableb)=>ca->Maybe(cb)gcastx=fmap(\Refl->x)(eqT::Maybe(a:~:b))-- | Cast over @k1 -> k2@gcast1::forallctt'a.(Typeablet,Typeablet')=>c(ta)->Maybe(c(t'a))gcast1x=fmap(\Refl->x)(eqT::Maybe(t:~:t'))-- | Cast over @k1 -> k2 -> k3@gcast2::forallctt'ab.(Typeablet,Typeablet')=>c(tab)->Maybe(c(t'ab))gcast2x=fmap(\Refl->x)(eqT::Maybe(t:~:t'))-- | Applies a type to a function type. Returns: @Just u@ if the first argument-- represents a function of type @t -> u@ and the second argument represents a-- function of type @t@. Otherwise, returns @Nothing@.funResultTy::TypeRep->TypeRep->MaybeTypeRepfunResultTy(I.SomeTypeRepf)(I.SomeTypeRepx)|JustHRefl<-(I.typeRep::I.TypeRepType)`I.eqTypeRep`I.typeRepKindf,I.Funargres<-f,JustHRefl<-arg`I.eqTypeRep`x=Just(I.SomeTypeRepres)|otherwise=Nothing-- | Build a function type.mkFunTy::TypeRep->TypeRep->TypeRepmkFunTy(I.SomeTypeReparg)(I.SomeTypeRepres)|JustHRefl<-I.typeRepKindarg`I.eqTypeRep`liftedTy,JustHRefl<-I.typeRepKindres`I.eqTypeRep`liftedTy=I.SomeTypeRep(I.Funargres)|otherwise=error$"mkFunTy: Attempted to construct function type from non-lifted "++"type: arg="++showarg++", res="++showreswhereliftedTy=I.typeRep::I.TypeRepType-- | Splits a type constructor application. Note that if the type constructor is-- polymorphic, this will not return the kinds that were used.splitTyConApp::TypeRep->(TyCon,[TypeRep])splitTyConApp(I.SomeTypeRepx)=I.splitAppsx-- | Observe the argument types of a type representationtypeRepArgs::TypeRep->[TypeRep]typeRepArgsty=casesplitTyConApptyof(_,args)->args-- | Observe the type constructor of a quantified type representation.typeRepTyCon::TypeRep->TyContypeRepTyCon=I.someTypeRepTyCon-- | Takes a value of type @a@ and returns a concrete representation-- of that type.---- @since 4.7.0.0typeRepFingerprint::TypeRep->FingerprinttypeRepFingerprint=I.someTypeRepFingerprint-- | Force a 'TypeRep' to normal form.rnfTypeRep::TypeRep->()rnfTypeRep=I.rnfSomeTypeRep-- Keeping backwards-compatibilitytypeOf1::forallt(a::Type).Typeablet=>ta->TypeReptypeOf1_=I.someTypeRep(Proxy::Proxyt)typeOf2::forallt(a::Type)(b::Type).Typeablet=>tab->TypeReptypeOf2_=I.someTypeRep(Proxy::Proxyt)typeOf3::forallt(a::Type)(b::Type)(c::Type).Typeablet=>tabc->TypeReptypeOf3_=I.someTypeRep(Proxy::Proxyt)typeOf4::forallt(a::Type)(b::Type)(c::Type)(d::Type).Typeablet=>tabcd->TypeReptypeOf4_=I.someTypeRep(Proxy::Proxyt)typeOf5::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type).Typeablet=>tabcde->TypeReptypeOf5_=I.someTypeRep(Proxy::Proxyt)typeOf6::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type)(f::Type).Typeablet=>tabcdef->TypeReptypeOf6_=I.someTypeRep(Proxy::Proxyt)typeOf7::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type)(f::Type)(g::Type).Typeablet=>tabcdefg->TypeReptypeOf7_=I.someTypeRep(Proxy::Proxyt)

[8]ページ先頭

©2009-2025 Movatter.jp