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.10, all types automatically have 'Typeable' instances derived.-- This is in contrast to previous releases where 'Typeable' had to be-- explicitly derived using the @DeriveDataTypeable@ language extension.---- 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://gitlab.haskell.org/ghc/ghc/wikis/ghc-kinds/poly-typeable 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 :: a -> TypeReptypeOfa_=Proxy a -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy aforall k (t :: k). Proxy tProxy::Proxya)-- | Takes a value of type @a@ and returns a concrete representation-- of that type.---- @since 4.7.0.0typeRep::forallproxya.Typeablea=>proxya->TypeReptypeRep :: proxy a -> TypeReptypeRep=proxy a -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep-- | Show a type representationshowsTypeRep::TypeRep->ShowSshowsTypeRep :: TypeRep -> ShowSshowsTypeRep=TypeRep -> ShowSforall a. Show a => a -> ShowSshows-- | The type-safe cast operationcast::forallab.(Typeablea,Typeableb)=>a->Maybebcast :: a -> Maybe bcastax|Justa :~~: bHRefl<-TypeRep ataTypeRep a -> TypeRep b -> Maybe (a :~~: b)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep btb=a -> Maybe aforall a. a -> Maybe aJustax|Boolotherwise=Maybe bforall a. Maybe aNothingwhereta :: TypeRep ata=TypeRep aforall k (a :: k). Typeable a => TypeRep aI.typeRep::I.TypeRepatb :: TypeRep btb=TypeRep bforall k (a :: k). Typeable a => TypeRep aI.typeRep::I.TypeRepb-- | Extract a witness of equality of two types---- @since 4.7.0.0eqT::forallab.(Typeablea,Typeableb)=>Maybe(a:~:b)eqT :: Maybe (a :~: b)eqT|Justa :~~: bHRefl<-TypeRep ataTypeRep a -> TypeRep b -> Maybe (a :~~: b)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep btb=(a :~: a) -> Maybe (a :~: a)forall a. a -> Maybe aJusta :~: aforall k (a :: k). a :~: aRefl|Boolotherwise=Maybe (a :~: b)forall a. Maybe aNothingwhereta :: TypeRep ata=TypeRep aforall k (a :: k). Typeable a => TypeRep aI.typeRep::I.TypeRepatb :: TypeRep btb=TypeRep bforall k (a :: k). Typeable a => TypeRep aI.typeRep::I.TypeRepb-- | A flexible variation parameterised in a type constructorgcast::forallabc.(Typeablea,Typeableb)=>ca->Maybe(cb)gcast :: c a -> Maybe (c b)gcastc ax=((a :~: b) -> c b) -> Maybe (a :~: b) -> Maybe (c b)forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmap(\a :~: bRefl->c ac bx)(Maybe (a :~: b)forall k (a :: k) (b :: k).(Typeable a, Typeable b) =>Maybe (a :~: b)eqT::Maybe(a:~:b))-- | Cast over @k1 -> k2@gcast1::forallctt'a.(Typeablet,Typeablet')=>c(ta)->Maybe(c(t'a))gcast1 :: c (t a) -> Maybe (c (t' a))gcast1c (t a)x=((t :~: t') -> c (t' a)) -> Maybe (t :~: t') -> Maybe (c (t' a))forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmap(\t :~: t'Refl->c (t a)c (t' a)x)(Maybe (t :~: t')forall k (a :: k) (b :: k).(Typeable a, Typeable b) =>Maybe (a :~: b)eqT::Maybe(t:~:t'))-- | Cast over @k1 -> k2 -> k3@gcast2::forallctt'ab.(Typeablet,Typeablet')=>c(tab)->Maybe(c(t'ab))gcast2 :: c (t a b) -> Maybe (c (t' a b))gcast2c (t a b)x=((t :~: t') -> c (t' a b))-> Maybe (t :~: t') -> Maybe (c (t' a b))forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f bfmap(\t :~: t'Refl->c (t a b)c (t' a b)x)(Maybe (t :~: t')forall k (a :: k) (b :: k).(Typeable a, Typeable b) =>Maybe (a :~: b)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 :: TypeRep -> TypeRep -> Maybe TypeRepfunResultTy(I.SomeTypeRepTypeRep af)(I.SomeTypeRepTypeRep ax)|Just* :~~: kHRefl<-(TypeRep *forall k (a :: k). Typeable a => TypeRep aI.typeRep::I.TypeRepType)TypeRep * -> TypeRep k -> Maybe (* :~~: k)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep a -> TypeRep kforall k (a :: k). TypeRep a -> TypeRep kI.typeRepKindTypeRep af,I.FunTypeRep argargTypeRep resres<-TypeRep af,Justarg :~~: aHRefl<-TypeRep argargTypeRep arg -> TypeRep a -> Maybe (arg :~~: a)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep ax=TypeRep -> Maybe TypeRepforall a. a -> Maybe aJust(TypeRep res -> TypeRepforall k (a :: k). TypeRep a -> TypeRepI.SomeTypeRepTypeRep resres)|Boolotherwise=Maybe TypeRepforall a. Maybe aNothing-- | Build a function type.mkFunTy::TypeRep->TypeRep->TypeRepmkFunTy :: TypeRep -> TypeRep -> TypeRepmkFunTy(I.SomeTypeRepTypeRep aarg)(I.SomeTypeRepTypeRep ares)|Justk :~~: *HRefl<-TypeRep a -> TypeRep kforall k (a :: k). TypeRep a -> TypeRep kI.typeRepKindTypeRep aargTypeRep k -> TypeRep * -> Maybe (k :~~: *)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep *liftedTy,Justk :~~: *HRefl<-TypeRep a -> TypeRep kforall k (a :: k). TypeRep a -> TypeRep kI.typeRepKindTypeRep aresTypeRep k -> TypeRep * -> Maybe (k :~~: *)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`I.eqTypeRep`TypeRep *liftedTy=TypeRep (a -> a) -> TypeRepforall k (a :: k). TypeRep a -> TypeRepI.SomeTypeRep(TypeRep a -> TypeRep a -> TypeRep (a -> a)forall k (fun :: k) arg res.(k ~ *, fun ~~ (arg -> res)) =>TypeRep arg -> TypeRep res -> TypeRep funI.FunTypeRep aTypeRep aargTypeRep aTypeRep ares)|Boolotherwise=[Char] -> TypeRepforall a. HasCallStack => [Char] -> aerror([Char] -> TypeRep) -> [Char] -> TypeRepforall a b. (a -> b) -> a -> b$[Char]"mkFunTy: Attempted to construct function type from non-lifted "[Char] -> ShowSforall a. [a] -> [a] -> [a]++[Char]"type: arg="[Char] -> ShowSforall a. [a] -> [a] -> [a]++TypeRep a -> [Char]forall a. Show a => a -> [Char]showTypeRep aarg[Char] -> ShowSforall a. [a] -> [a] -> [a]++[Char]", res="[Char] -> ShowSforall a. [a] -> [a] -> [a]++TypeRep a -> [Char]forall a. Show a => a -> [Char]showTypeRep areswhereliftedTy :: TypeRep *liftedTy=TypeRep *forall k (a :: k). Typeable a => TypeRep aI.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 :: TypeRep -> (TyCon, [TypeRep])splitTyConApp(I.SomeTypeRepTypeRep ax)=TypeRep a -> (TyCon, [TypeRep])forall k (a :: k). TypeRep a -> (TyCon, [TypeRep])I.splitAppsTypeRep ax-- | Observe the argument types of a type representationtypeRepArgs::TypeRep->[TypeRep]typeRepArgs :: TypeRep -> [TypeRep]typeRepArgsTypeRepty=caseTypeRep -> (TyCon, [TypeRep])splitTyConAppTypeReptyof(TyCon_,[TypeRep]args)->[TypeRep]args-- | Observe the type constructor of a quantified type representation.typeRepTyCon::TypeRep->TyContypeRepTyCon :: TypeRep -> TyContypeRepTyCon=TypeRep -> TyConI.someTypeRepTyCon-- | Takes a value of type @a@ and returns a concrete representation-- of that type.---- @since 4.7.0.0typeRepFingerprint::TypeRep->FingerprinttypeRepFingerprint :: TypeRep -> FingerprinttypeRepFingerprint=TypeRep -> FingerprintI.someTypeRepFingerprint-- | Force a 'TypeRep' to normal form.rnfTypeRep::TypeRep->()rnfTypeRep :: TypeRep -> ()rnfTypeRep=TypeRep -> ()I.rnfSomeTypeRep-- Keeping backwards-compatibilitytypeOf1::forallt(a::Type).Typeablet=>ta->TypeReptypeOf1 :: t a -> TypeReptypeOf1t a_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf2::forallt(a::Type)(b::Type).Typeablet=>tab->TypeReptypeOf2 :: t a b -> TypeReptypeOf2t a b_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf3::forallt(a::Type)(b::Type)(c::Type).Typeablet=>tabc->TypeReptypeOf3 :: t a b c -> TypeReptypeOf3t a b c_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf4::forallt(a::Type)(b::Type)(c::Type)(d::Type).Typeablet=>tabcd->TypeReptypeOf4 :: t a b c d -> TypeReptypeOf4t a b c d_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf5::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type).Typeablet=>tabcde->TypeReptypeOf5 :: t a b c d e -> TypeReptypeOf5t a b c d e_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf6::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type)(f::Type).Typeablet=>tabcdef->TypeReptypeOf6 :: t a b c d e f -> TypeReptypeOf6t a b c d e f_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)typeOf7::forallt(a::Type)(b::Type)(c::Type)(d::Type)(e::Type)(f::Type)(g::Type).Typeablet=>tabcdefg->TypeReptypeOf7 :: t a b c d e f g -> TypeReptypeOf7t a b c d e f g_=Proxy t -> TypeRepforall k (proxy :: k -> *) (a :: k).Typeable a =>proxy a -> TypeRepI.someTypeRep(Proxy tforall k (t :: k). Proxy tProxy::Proxyt)

[8]ページ先頭

©2009-2025 Movatter.jp