Movatterモバイル変換
[0]ホーム
{-# LANGUAGE AllowAmbiguousTypes #-}{-# LANGUAGE Trustworthy #-}{-# LANGUAGE ViewPatterns #-}{-# LANGUAGE TypeOperators #-}{-# LANGUAGE BangPatterns #-}{-# LANGUAGE RankNTypes #-}{-# LANGUAGE PatternSynonyms #-}{-# LANGUAGE CPP #-}{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE FlexibleInstances #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE MagicHash #-}{-# LANGUAGE NoImplicitPrelude #-}{-# LANGUAGE PolyKinds #-}{-# LANGUAGE ScopedTypeVariables #-}{-# LANGUAGE StandaloneDeriving #-}{-# LANGUAGE UndecidableInstances #-}{-# LANGUAGE TypeApplications #-}{-# LANGUAGE TypeFamilies #-}{-# LANGUAGE StandaloneKindSignatures #-}------------------------------------------------------------------------------- |-- Module : Data.Typeable.Internal-- Copyright : (c) The University of Glasgow, CWI 2001--2011-- License : BSD-style (see the file libraries/base/LICENSE)---- The representations of the types TyCon and TypeRep, and the-- function mkTyCon which is used by derived instances of Typeable to-- construct a TyCon.-------------------------------------------------------------------------------moduleData.Typeable.Internal(-- * Typeable and kind polymorphism---- #kind_instantiation-- * MiscellaneousFingerprint(..),-- * Typeable classTypeable(..),withTypeable,-- * ModuleModule,-- AbstractmoduleName,modulePackage,rnfModule,-- * TyConTyCon,-- AbstracttyConPackage,tyConModule,tyConName,tyConKindArgs,tyConKindRep,tyConFingerprint,KindRep(..,KindRepTypeLit),TypeLitSort(..),rnfTyCon,-- * TypeRepTypeRep,patternApp,patternCon,patternCon',patternFun,typeRep,typeOf,typeRepTyCon,typeRepFingerprint,rnfTypeRep,eqTypeRep,typeRepKind,splitApps,-- * SomeTypeRepSomeTypeRep(..),someTypeRep,someTypeRepTyCon,someTypeRepFingerprint,rnfSomeTypeRep,-- * Construction-- | These are for internal use onlymkTrType,mkTrCon,mkTrApp,mkTrAppChecked,mkTrFun,mkTyCon,mkTyCon#,typeSymbolTypeRep,typeNatTypeRep,)whereimportGHC.BaseimportqualifiedGHC.ArrasAimportGHC.Types(TYPE)importData.Type.EqualityimportGHC.List(splitAt,foldl',elem)importGHC.WordimportGHC.ShowimportGHC.TypeLits(KnownSymbol,symbolVal',AppendSymbol)importGHC.TypeNats(KnownNat,natVal')importUnsafe.Coerce(unsafeCoerce)importGHC.Fingerprint.Typeimport{-# SOURCE#-}GHC.Fingerprint-- loop: GHC.Fingerprint -> Foreign.Ptr -> Data.Typeable-- Better to break the loop here, because we want non-SOURCE imports-- of Data.Typeable as much as possible so we can optimise the derived-- instances.-- import {-# SOURCE #-} Debug.Trace (trace)#include "MachDeps.h"{- ********************************************************************** * The TyCon type* ********************************************************************** -}modulePackage::Module->StringmodulePackage :: Module -> StringmodulePackage(ModuleTrNamepTrName_)=TrName -> StringtrNameStringTrNamepmoduleName::Module->StringmoduleName :: Module -> StringmoduleName(ModuleTrName_TrNamem)=TrName -> StringtrNameStringTrNamemtyConPackage::TyCon->StringtyConPackage :: TyCon -> StringtyConPackage(TyConWord#_Word#_ModulemTrName_Int#_KindRep_)=Module -> StringmodulePackageModulemtyConModule::TyCon->StringtyConModule :: TyCon -> StringtyConModule(TyConWord#_Word#_ModulemTrName_Int#_KindRep_)=Module -> StringmoduleNameModulemtyConName::TyCon->StringtyConName :: TyCon -> StringtyConName(TyConWord#_Word#_Module_TrNamenInt#_KindRep_)=TrName -> StringtrNameStringTrNamentrNameString::TrName->StringtrNameString :: TrName -> StringtrNameString(TrNameSAddr#s)=Addr# -> StringunpackCStringUtf8#Addr#strNameString(TrNameDStrings)=StringstyConFingerprint::TyCon->FingerprinttyConFingerprint :: TyCon -> FingerprinttyConFingerprint(TyConWord#hiWord#loModule_TrName_Int#_KindRep_)=Word64 -> Word64 -> FingerprintFingerprint(Word# -> Word64W64#Word#hi)(Word# -> Word64W64#Word#lo)tyConKindArgs::TyCon->InttyConKindArgs :: TyCon -> InttyConKindArgs(TyConWord#_Word#_Module_TrName_Int#nKindRep_)=Int# -> IntI#Int#ntyConKindRep::TyCon->KindReptyConKindRep :: TyCon -> KindReptyConKindRep(TyConWord#_Word#_Module_TrName_Int#_KindRepk)=KindRepk-- | Helper to fully evaluate 'TyCon' for use as @NFData(rnf)@ implementation---- @since 4.8.0.0rnfModule::Module->()rnfModule :: Module -> ()rnfModule(ModuleTrNamepTrNamem)=TrName -> ()rnfTrNameTrNamep() -> () -> ()`seq`TrName -> ()rnfTrNameTrNamemrnfTrName::TrName->()rnfTrName :: TrName -> ()rnfTrName(TrNameSAddr#_)=()rnfTrName(TrNameDStringn)=String -> ()rnfStringStringnrnfKindRep::KindRep->()rnfKindRep :: KindRep -> ()rnfKindRep(KindRepTyConAppTyContc[KindRep]args)=TyCon -> ()rnfTyConTyContc() -> () -> ()`seq`(KindRep -> ()) -> [KindRep] -> ()forall a. (a -> ()) -> [a] -> ()rnfListKindRep -> ()rnfKindRep[KindRep]argsrnfKindRep(KindRepVarInt_)=()rnfKindRep(KindRepAppKindRepaKindRepb)=KindRep -> ()rnfKindRepKindRepa() -> () -> ()`seq`KindRep -> ()rnfKindRepKindRepbrnfKindRep(KindRepFunKindRepaKindRepb)=KindRep -> ()rnfKindRepKindRepa() -> () -> ()`seq`KindRep -> ()rnfKindRepKindRepbrnfKindRep(KindRepTYPERuntimeReprr)=RuntimeRep -> ()rnfRuntimeRepRuntimeReprrrnfKindRep(KindRepTypeLitSTypeLitSort_Addr#_)=()rnfKindRep(KindRepTypeLitDTypeLitSort_Stringt)=String -> ()rnfStringStringtrnfRuntimeRep::RuntimeRep->()rnfRuntimeRep :: RuntimeRep -> ()rnfRuntimeRep(VecRep!VecCount_!VecElem_)=()rnfRuntimeRep!RuntimeRep_=()rnfList::(a->())->[a]->()rnfList :: (a -> ()) -> [a] -> ()rnfLista -> ()_[]=()rnfLista -> ()force(ax:[a]xs)=a -> ()forceax() -> () -> ()`seq`(a -> ()) -> [a] -> ()forall a. (a -> ()) -> [a] -> ()rnfLista -> ()force[a]xsrnfString::[Char]->()rnfString :: String -> ()rnfString=(Char -> ()) -> String -> ()forall a. (a -> ()) -> [a] -> ()rnfList(Char -> () -> ()`seq`())rnfTyCon::TyCon->()rnfTyCon :: TyCon -> ()rnfTyCon(TyConWord#_Word#_ModulemTrNamenInt#_KindRepk)=Module -> ()rnfModuleModulem() -> () -> ()`seq`TrName -> ()rnfTrNameTrNamen() -> () -> ()`seq`KindRep -> ()rnfKindRepKindRepk{- ********************************************************************** * The TypeRep type* ********************************************************************** -}-- | A concrete representation of a (monomorphic) type.-- 'TypeRep' supports reasonably efficient equality.typeTypeRep::k->TypedataTypeRepawhere-- The TypeRep of Type. See Note [Kind caching], Wrinkle 2TrType::TypeRepTypeTrTyCon::{-- See Note [TypeRep fingerprints]TypeRep a -> FingerprinttrTyConFingerprint::{-# UNPACK#-}!Fingerprint-- The TypeRep represents the application of trTyCon-- to the kind arguments trKindVars. So for-- 'Just :: Bool -> Maybe Bool, the trTyCon will be-- 'Just and the trKindVars will be [Bool].,TypeRep a -> TyContrTyCon::!TyCon,TypeRep a -> [SomeTypeRep]trKindVars::[SomeTypeRep],TypeRep a -> TypeRep ktrTyConKind::!(TypeRepk)}-- See Note [Kind caching]->TypeRep(a::k)-- | Invariant: Saturated arrow types (e.g. things of the form @a -> b@)-- are represented with @'TrFun' a b@, not @TrApp (TrApp funTyCon a) b@.TrApp::forallk1k2(a::k1->k2)(b::k1).{-- See Note [TypeRep fingerprints]TypeRep (a b) -> FingerprinttrAppFingerprint::{-# UNPACK#-}!Fingerprint-- The TypeRep represents the application of trAppFun-- to trAppArg. For Maybe Int, the trAppFun will be Maybe-- and the trAppArg will be Int.,TypeRep (a b) -> TypeRep atrAppFun::!(TypeRep(a::k1->k2)),TypeRep (a b) -> TypeRep btrAppArg::!(TypeRep(b::k1)),TypeRep (a b) -> TypeRep k2trAppKind::!(TypeRepk2)}-- See Note [Kind caching]->TypeRep(ab)-- | @TrFun fpr a b@ represents a function type @a -> b@. We use this for-- the sake of efficiency as functions are quite ubiquitous.TrFun::forall(r1::RuntimeRep)(r2::RuntimeRep)(a::TYPEr1)(b::TYPEr2).{-- See Note [TypeRep fingerprints]TypeRep (a -> b) -> FingerprinttrFunFingerprint::{-# UNPACK#-}!Fingerprint-- The TypeRep represents a function from trFunArg to-- trFunRes.,TypeRep (a -> b) -> TypeRep atrFunArg::!(TypeRepa),TypeRep (a -> b) -> TypeRep btrFunRes::!(TypeRepb)}->TypeRep(a->b){- Note [TypeRep fingerprints] ~~~~~~~~~~~~~~~~~~~~~~~~~~~We store a Fingerprint of each TypeRep in its constructor. This allowsus to test whether two TypeReps are equal in constant time, rather thanhaving to walk their full structures.-}{- Note [Kind caching] ~~~~~~~~~~~~~~~~~~~We cache the kind of the TypeRep in each TrTyCon and TrApp constructor.This is necessary to ensure that typeRepKind (which is used, at least, indeserialization and dynApply) is cheap. There are two reasons for this:1. Calculating the kind of a nest of type applications, such as F X Y Z W (App (App (App (App F X) Y) Z) W)is linear in the depth, which is already a bit pricy. In deserialization,we build up such a nest from the inside out, so without caching, that endsup taking quadratic time, and calculating the KindRep of the constructor,F, a linear number of times. See #14254.2. Calculating the kind of a type constructor, in instantiateTypeRep,requires building (allocating) a TypeRep for the kind "from scratch".This can get pricy. When combined with point (1), we can end up witha large amount of extra allocation deserializing very deep nests.See #14337.It is quite possible to speed up deserialization by structuring that processvery carefully. Unfortunately, that doesn't help dynApply or anything elsethat may use typeRepKind. Since caching the kind isn't terribly expensive, itseems better to just do that and solve all the potential problems at once.There are two things we need to be careful about when caching kinds.Wrinkle 1:We want to do it eagerly. Suppose we have tf :: TypeRep (f :: j -> k) ta :: TypeRep (a :: j)Then the cached kind of App tf ta should be eagerly evaluated to k, ratherthan being stored as a thunk that will strip the (j ->) off of j -> k ifand when it is forced.Wrinkle 2:We need to be able to represent TypeRep Type. This is a bit tricky becausetypeRepKind (typeRep @Type) = typeRep @Type, so if we actually cache thetyperep of the kind of Type, we will have a loop. One simple way to do thisis to make the cached kind fields lazy and allow TypeRep Type to be cyclical.But we *do not* want TypeReps to have cyclical structure! Most importantly,a cyclical structure cannot be stored in a compact region. Secondarily,using :force in GHCi on a cyclical structure will lead to non-termination.To avoid this trouble, we use a separate constructor for TypeRep Type.mkTrApp is responsible for recognizing that TYPE is being applied to'LiftedRep and produce trType; other functions must recognize that TrTyperepresents an application.-}-- Compare keys for equality-- | @since 2.01instanceEq(TypeRepa)whereTypeRep a_== :: TypeRep a -> TypeRep a -> Bool==TypeRep a_=BoolTrue{-# INLINABLE(==)#-}instanceTestEqualityTypeRepwhereTypeRep aatestEquality :: TypeRep a -> TypeRep b -> Maybe (a :~: b)`testEquality`TypeRep bb|Justa :~~: bHRefl<-TypeRep a -> TypeRep b -> Maybe (a :~~: b)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)eqTypeRepTypeRep aaTypeRep bb=(a :~: a) -> Maybe (a :~: a)forall a. a -> Maybe aJusta :~: aforall k (a :: k). a :~: aRefl|Boolotherwise=Maybe (a :~: b)forall a. Maybe aNothing{-# INLINEABLEtestEquality#-}-- | @since 4.4.0.0instanceOrd(TypeRepa)wherecompare :: TypeRep a -> TypeRep a -> OrderingcompareTypeRep a_TypeRep a_=OrderingEQ{-# INLINABLEcompare#-}-- | A non-indexed type representation.dataSomeTypeRepwhereSomeTypeRep::forallk(a::k).!(TypeRepa)->SomeTypeRepinstanceEqSomeTypeRepwhereSomeTypeRepTypeRep aa== :: SomeTypeRep -> SomeTypeRep -> Bool==SomeTypeRepTypeRep ab=caseTypeRep aaTypeRep a -> TypeRep a -> Maybe (a :~~: a)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`TypeRep abofJusta :~~: a_->BoolTrueMaybe (a :~~: a)Nothing->BoolFalseinstanceOrdSomeTypeRepwhereSomeTypeRepTypeRep aacompare :: SomeTypeRep -> SomeTypeRep -> Ordering`compare`SomeTypeRepTypeRep ab=TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep aaFingerprint -> Fingerprint -> Orderingforall a. Ord a => a -> a -> Ordering`compare`TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep ab-- | The function type constructor.---- For instance,---- @-- typeRep \@(Int -> Char) === Fun (typeRep \@Int) (typeRep \@Char)-- @--patternFun::forallk(fun::k).()=>forall(r1::RuntimeRep)(r2::RuntimeRep)(arg::TYPEr1)(res::TYPEr2).(k~Type,fun~~(arg->res))=>TypeReparg->TypeRepres->TypeRepfunpattern$bFun :: TypeRep arg -> TypeRep res -> TypeRep fun$mFun :: forall r k (fun :: k).TypeRep fun-> (forall arg res. (k ~ *, fun ~~ (arg -> res)) => TypeRep arg -> TypeRep res -> r)-> (Void# -> r)-> rFunargres<-TrFun{trFunArg=arg,trFunRes=res}whereFunTypeRep argargTypeRep resres=TypeRep arg -> TypeRep res -> TypeRep (arg -> res)forall a b. TypeRep a -> TypeRep b -> TypeRep (a -> b)mkTrFunTypeRep argargTypeRep resres-- | Observe the 'Fingerprint' of a type representation---- @since 4.8.0.0typeRepFingerprint::TypeRepa->FingerprinttypeRepFingerprint :: TypeRep a -> FingerprinttypeRepFingerprintTypeRep aTrType=FingerprintfpTYPELiftedReptypeRepFingerprint(TrTyCon{trTyConFingerprint :: forall k (a :: k). TypeRep a -> FingerprinttrTyConFingerprint=Fingerprintfpr})=FingerprintfprtypeRepFingerprint(TrApp{trAppFingerprint :: forall k2 k1 (a :: k1 -> k2) (b :: k1).TypeRep (a b) -> FingerprinttrAppFingerprint=Fingerprintfpr})=FingerprintfprtypeRepFingerprint(TrFun{trFunFingerprint :: forall a b. TypeRep (a -> b) -> FingerprinttrFunFingerprint=Fingerprintfpr})=Fingerprintfpr-- For compiler usemkTrType::TypeRepTypemkTrType :: TypeRep *mkTrType=TypeRep *TrType-- | Construct a representation for a type constructor-- applied at a monomorphic kind.---- Note that this is unsafe as it allows you to construct-- ill-kinded types.mkTrCon::forallk(a::k).TyCon->[SomeTypeRep]->TypeRepamkTrCon :: TyCon -> [SomeTypeRep] -> TypeRep amkTrConTyContc[SomeTypeRep]kind_vars=TrTyCon :: forall k (a :: k).Fingerprint -> TyCon -> [SomeTypeRep] -> TypeRep k -> TypeRep aTrTyCon{trTyConFingerprint :: FingerprinttrTyConFingerprint=Fingerprintfpr,trTyCon :: TyContrTyCon=TyContc,trKindVars :: [SomeTypeRep]trKindVars=[SomeTypeRep]kind_vars,trTyConKind :: TypeRep ktrTyConKind=TypeRep kkind}wherefpr_tc :: Fingerprintfpr_tc=TyCon -> FingerprinttyConFingerprintTyContcfpr_kvs :: [Fingerprint]fpr_kvs=(SomeTypeRep -> Fingerprint) -> [SomeTypeRep] -> [Fingerprint]forall a b. (a -> b) -> [a] -> [b]mapSomeTypeRep -> FingerprintsomeTypeRepFingerprint[SomeTypeRep]kind_varsfpr :: Fingerprintfpr=[Fingerprint] -> FingerprintfingerprintFingerprints(Fingerprintfpr_tcFingerprint -> [Fingerprint] -> [Fingerprint]forall a. a -> [a] -> [a]:[Fingerprint]fpr_kvs)kind :: TypeRep kkind=SomeTypeRep -> TypeRep kforall k (a :: k). SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRep -> TypeRep k) -> SomeTypeRep -> TypeRep kforall a b. (a -> b) -> a -> b$TyCon -> [SomeTypeRep] -> SomeTypeReptyConKindTyContc[SomeTypeRep]kind_vars-- The fingerprint of Type. We don't store this in the TrType-- constructor, so we need to build it here.fpTYPELiftedRep::FingerprintfpTYPELiftedRep :: FingerprintfpTYPELiftedRep=[Fingerprint] -> FingerprintfingerprintFingerprints[TyCon -> FingerprinttyConFingerprintTyContyConTYPE,TypeRep 'LiftedRep -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep 'LiftedReptrLiftedRep]-- There is absolutely nothing to gain and everything to lose-- by inlining the worker. The wrapper should inline anyway.{-# NOINLINEfpTYPELiftedRep#-}trTYPE::TypeRepTYPEtrTYPE :: TypeRep TYPEtrTYPE=TypeRep TYPEforall k (a :: k). Typeable a => TypeRep atypeReptrLiftedRep::TypeRep'LiftedReptrLiftedRep :: TypeRep 'LiftedReptrLiftedRep=TypeRep 'LiftedRepforall k (a :: k). Typeable a => TypeRep atypeRep-- | Construct a representation for a type application that is-- NOT a saturated arrow type. This is not checked!-- Note that this is known-key to the compiler, which uses it in desugar-- 'Typeable' evidence.mkTrApp::forallk1k2(a::k1->k2)(b::k1).TypeRep(a::k1->k2)->TypeRep(b::k1)->TypeRep(ab)mkTrApp :: TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppTypeRep aaTypeRep bb-- See Note [Kind caching], Wrinkle 2|Justa :~~: TYPEHRefl<-TypeRep aaTypeRep a -> TypeRep TYPE -> Maybe (a :~~: TYPE)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`TypeRep TYPEtrTYPE,Justb :~~: 'LiftedRepHRefl<-TypeRep bbTypeRep b -> TypeRep 'LiftedRep -> Maybe (b :~~: 'LiftedRep)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`TypeRep 'LiftedReptrLiftedRep=TypeRep (a b)TypeRep *TrType|TrFun{trFunRes :: forall a b. TypeRep (a -> b) -> TypeRep btrFunRes=TypeRep bres_kind}<-TypeRep a -> TypeRep (k1 -> k2)forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep aa=TrApp :: forall k1 k2 (a :: k1 -> k2) (b :: k1).Fingerprint-> TypeRep a -> TypeRep b -> TypeRep k2 -> TypeRep (a b)TrApp{trAppFingerprint :: FingerprinttrAppFingerprint=Fingerprintfpr,trAppFun :: TypeRep atrAppFun=TypeRep aa,trAppArg :: TypeRep btrAppArg=TypeRep bb,trAppKind :: TypeRep k2trAppKind=TypeRep bTypeRep k2res_kind}|Boolotherwise=String -> TypeRep (a b)forall a. HasCallStack => String -> aerror(String"Ill-kinded type application: "String -> String -> Stringforall a. [a] -> [a] -> [a]++TypeRep (k1 -> k2) -> Stringforall a. Show a => a -> Stringshow(TypeRep a -> TypeRep (k1 -> k2)forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep aa))wherefpr_a :: Fingerprintfpr_a=TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep aafpr_b :: Fingerprintfpr_b=TypeRep b -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep bbfpr :: Fingerprintfpr=[Fingerprint] -> FingerprintfingerprintFingerprints[Fingerprintfpr_a,Fingerprintfpr_b]-- | Construct a representation for a type application that-- may be a saturated arrow type. This is renamed to mkTrApp in-- Type.Reflection.UnsafemkTrAppChecked::forallk1k2(a::k1->k2)(b::k1).TypeRep(a::k1->k2)->TypeRep(b::k1)->TypeRep(ab)mkTrAppChecked :: TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppCheckedrep :: TypeRep arep@(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep ap,trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep bx::TypeRepx})(TypeRep by::TypeRepy)|TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyConcon}<-TypeRep ap,TyConconTyCon -> TyCon -> Boolforall a. Eq a => a -> a -> Bool==TyConfunTyCon-- cheap check first,Just(IsTYPE(TypeRep rrx::TypeReprx))<-TypeRep k1 -> Maybe (IsTYPE k1)forall a. TypeRep a -> Maybe (IsTYPE a)isTYPE(TypeRep b -> TypeRep k1forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep bx),Just(IsTYPE(TypeRep rry::TypeRepry))<-TypeRep k1 -> Maybe (IsTYPE k1)forall a. TypeRep a -> Maybe (IsTYPE a)isTYPE(TypeRep b -> TypeRep k1forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep by),Just(->) b :~~: a bHRefl<-TypeRep b-> (Typeable b => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall k (a :: k) r. TypeRep a -> (Typeable a => r) -> rwithTypeableTypeRep bx((Typeable b => Maybe ((->) b :~~: a b)) -> Maybe ((->) b :~~: a b))-> (Typeable b => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall a b. (a -> b) -> a -> b$TypeRep r-> (Typeable r => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall k (a :: k) r. TypeRep a -> (Typeable a => r) -> rwithTypeableTypeRep rrx((Typeable r => Maybe ((->) b :~~: a b)) -> Maybe ((->) b :~~: a b))-> (Typeable r => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall a b. (a -> b) -> a -> b$TypeRep r-> (Typeable r => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall k (a :: k) r. TypeRep a -> (Typeable a => r) -> rwithTypeableTypeRep rry((Typeable r => Maybe ((->) b :~~: a b)) -> Maybe ((->) b :~~: a b))-> (Typeable r => Maybe ((->) b :~~: a b))-> Maybe ((->) b :~~: a b)forall a b. (a -> b) -> a -> b$Typeable ((->) b) => TypeRep ((->) b)forall k (a :: k). Typeable a => TypeRep atypeRep@((->)x::TYPEry->Type)TypeRep ((->) b) -> TypeRep a -> Maybe ((->) b :~~: a)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`TypeRep arep=TypeRep b -> TypeRep b -> TypeRep (b -> b)forall a b. TypeRep a -> TypeRep b -> TypeRep (a -> b)mkTrFunTypeRep bTypeRep bxTypeRep bTypeRep bymkTrAppCheckedTypeRep aaTypeRep bb=TypeRep a -> TypeRep b -> TypeRep (a b)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppTypeRep aaTypeRep bb-- | A type application.---- For instance,---- @-- typeRep \@(Maybe Int) === App (typeRep \@Maybe) (typeRep \@Int)-- @---- Note that this will also match a function type,---- @-- typeRep \@(Int# -> Char)-- ===-- App (App arrow (typeRep \@Int#)) (typeRep \@Char)-- @---- where @arrow :: TypeRep ((->) :: TYPE IntRep -> Type -> Type)@.--patternApp::forallk2(t::k2).()=>forallk1(a::k1->k2)(b::k1).(t~ab)=>TypeRepa->TypeRepb->TypeReptpattern$bApp :: TypeRep a -> TypeRep b -> TypeRep t$mApp :: forall r k2 (t :: k2).TypeRep t-> (forall k1 (a :: k1 -> k2) (b :: k1). (t ~ a b) => TypeRep a -> TypeRep b -> r)-> (Void# -> r)-> rAppfx<-(splitApp->IsAppfx)whereAppTypeRep afTypeRep bx=TypeRep a -> TypeRep b -> TypeRep (a b)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppCheckedTypeRep afTypeRep bxdataAppOrCon(a::k)whereIsApp::forallkk'(f::k'->k)(x::k').()=>TypeRepf->TypeRepx->AppOrCon(fx)-- See Note [Con evidence]IsCon::IsApplicationa~""=>TyCon->[SomeTypeRep]->AppOrConatypefamilyIsApplication(x::k)::SymbolwhereIsApplication(__)="An error message about this unifying with \"\" "`AppendSymbol`"means that you tried to match a TypeRep with Con or "`AppendSymbol`"Con' when the represented type was known to be an "`AppendSymbol`"application."IsApplication_=""splitApp::forallk(a::k).()=>TypeRepa->AppOrConasplitApp :: TypeRep a -> AppOrCon asplitAppTypeRep aTrType=TypeRep TYPE -> TypeRep 'LiftedRep -> AppOrCon *forall k k' (f :: k' -> k) (k :: k').TypeRep f -> TypeRep k -> AppOrCon (f k)IsAppTypeRep TYPEtrTYPETypeRep 'LiftedReptrLiftedRepsplitApp(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep af,trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep bx})=TypeRep a -> TypeRep b -> AppOrCon (a b)forall k k' (f :: k' -> k) (k :: k').TypeRep f -> TypeRep k -> AppOrCon (f k)IsAppTypeRep afTypeRep bxsplitApprep :: TypeRep arep@(TrFun{trFunArg :: forall a b. TypeRep (a -> b) -> TypeRep atrFunArg=TypeRep aa,trFunRes :: forall a b. TypeRep (a -> b) -> TypeRep btrFunRes=TypeRep bb})=TypeRep ((->) a) -> TypeRep b -> AppOrCon (a -> b)forall k k' (f :: k' -> k) (k :: k').TypeRep f -> TypeRep k -> AppOrCon (f k)IsApp(TypeRep (->) -> TypeRep a -> TypeRep ((->) a)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppTypeRep (->)arrTypeRep aa)TypeRep bbwherearr :: TypeRep (->)arr=TypeRep (a -> b) -> TypeRep (->)forall a b. TypeRep (a -> b) -> TypeRep (->)bareArrowTypeRep aTypeRep (a -> b)repsplitApp(TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyConcon,trKindVars :: forall k (a :: k). TypeRep a -> [SomeTypeRep]trKindVars=[SomeTypeRep]kinds})=case(Any :~: Any) -> IsApplication a :~: ""forall a b. a -> bunsafeCoerceAny :~: Anyforall k (a :: k). a :~: aRefl::IsApplicationa:~:""ofIsApplication a :~: ""Refl->TyCon -> [SomeTypeRep] -> AppOrCon aforall k (a :: k).(IsApplication a ~ "") =>TyCon -> [SomeTypeRep] -> AppOrCon aIsConTyConcon[SomeTypeRep]kinds-- | Use a 'TypeRep' as 'Typeable' evidence.withTypeable::forallk(a::k)rep(r::TYPErep).()=>TypeRepa->(Typeablea=>r)->rwithTypeable :: TypeRep a -> (Typeable a => r) -> rwithTypeableTypeRep arepTypeable a => rk=Gift a r -> TypeRep a -> rforall a b. a -> bunsafeCoerceGift a rk'TypeRep arepwherek'::Giftark' :: Gift a rk'=(Typeable a => r) -> Gift a rforall k (a :: k) r. (Typeable a => r) -> Gift a rGiftTypeable a => rk-- | A helper to satisfy the type checker in 'withTypeable'.newtypeGifta(r::TYPErep)=Gift(Typeablea=>r)-- | Pattern match on a type constructorpatternCon::forallk(a::k).()=>IsApplicationa~""-- See Note [Con evidence]=>TyCon->TypeRepapattern$mCon :: forall r k (a :: k).TypeRep a-> ((IsApplication a ~ "") => TyCon -> r) -> (Void# -> r) -> rConcon<-(splitApp->IsConcon_)-- | Pattern match on a type constructor including its instantiated kind-- variables.---- For instance,---- @-- App (Con' proxyTyCon ks) intRep = typeRep @(Proxy \@Int)-- @---- will bring into scope,---- @-- proxyTyCon :: TyCon-- ks == [someTypeRep @Type] :: [SomeTypeRep]-- intRep == typeRep @Int-- @--patternCon'::forallk(a::k).()=>IsApplicationa~""-- See Note [Con evidence]=>TyCon->[SomeTypeRep]->TypeRepapattern$mCon' :: forall r k (a :: k).TypeRep a-> ((IsApplication a ~ "") => TyCon -> [SomeTypeRep] -> r)-> (Void# -> r)-> rCon'conks<-(splitApp->IsConconks)-- TODO: Remove Fun when #14253 is fixed{-# COMPLETEFun,App,Con#-}{-# COMPLETEFun,App,Con'#-}{- Note [Con evidence] ~~~~~~~~~~~~~~~~~~~Matching TypeRep t on Con or Con' fakes up evidence that IsApplication t ~ "".Why should anyone care about the value of strange internal type family?Well, almost nobody cares about it, but the pattern checker does!For example, suppose we have TypeRep (f x) and we want to getTypeRep f and TypeRep x. There is no chance that the Con constructorwill match, because (f x) is not a constructor, but without theIsApplication evidence, omitting it will lead to an incomplete patternwarning. With the evidence, the pattern checker will see thatCon wouldn't typecheck, so everything works out as it should.Why do we use Symbols? We would really like to use something like type family NotApplication (t :: k) :: Constraint where NotApplication (f a) = TypeError ... NotApplication _ = ()Unfortunately, #11503 means that the pattern checker and type checkerwill fail to actually reject the mistaken patterns. So we describe theerror in the result type. It's a horrible hack.-}----------------- Observation ----------------------- | Observe the type constructor of a quantified type representation.someTypeRepTyCon::SomeTypeRep->TyConsomeTypeRepTyCon :: SomeTypeRep -> TyConsomeTypeRepTyCon(SomeTypeRepTypeRep at)=TypeRep a -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyConTypeRep at-- | Observe the type constructor of a type representationtypeRepTyCon::TypeRepa->TyContypeRepTyCon :: TypeRep a -> TyContypeRepTyConTypeRep aTrType=TyContyConTYPEtypeRepTyCon(TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyContc})=TyContctypeRepTyCon(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep aa})=TypeRep a -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyConTypeRep aatypeRepTyCon(TrFun{})=TypeRep (->) -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(TypeRep (->) -> TyCon) -> TypeRep (->) -> TyConforall a b. (a -> b) -> a -> b$Typeable (->) => TypeRep (->)forall k (a :: k). Typeable a => TypeRep atypeRep@(->)-- | Type equality---- @since 4.10eqTypeRep::forallk1k2(a::k1)(b::k2).TypeRepa->TypeRepb->Maybe(a:~~:b)eqTypeRep :: TypeRep a -> TypeRep b -> Maybe (a :~~: b)eqTypeRepTypeRep aaTypeRep bb|TypeRep a -> TypeRep b -> Boolforall k1 k2 (a :: k1) (b :: k2). TypeRep a -> TypeRep b -> BoolsameTypeRepTypeRep aaTypeRep bb=(a :~~: b) -> Maybe (a :~~: b)forall a. a -> Maybe aJust((Any :~~: Any) -> a :~~: bunsafeCoerce#Any :~~: Anyforall k2 (a :: k2). a :~~: aHRefl)|Boolotherwise=Maybe (a :~~: b)forall a. Maybe aNothing-- We want GHC to inline eqTypeRep to get rid of the Maybe-- in the usual case that it is scrutinized immediately. We-- split eqTypeRep into a worker and wrapper because otherwise-- it's much larger than anything we'd want to inline.{-# INLINABLEeqTypeRep#-}sameTypeRep::forallk1k2(a::k1)(b::k2).TypeRepa->TypeRepb->BoolsameTypeRep :: TypeRep a -> TypeRep b -> BoolsameTypeRepTypeRep aaTypeRep bb=TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep aaFingerprint -> Fingerprint -> Boolforall a. Eq a => a -> a -> Bool==TypeRep b -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep bb----------------------------------------------------------------- Computing kinds----------------------------------------------------------------- | Observe the kind of a type.typeRepKind::TypeRep(a::k)->TypeRepktypeRepKind :: TypeRep a -> TypeRep ktypeRepKindTypeRep aTrType=TypeRep kTypeRep *TrTypetypeRepKind(TrTyCon{trTyConKind :: forall k (a :: k). TypeRep a -> TypeRep ktrTyConKind=TypeRep kkind})=TypeRep kkindtypeRepKind(TrApp{trAppKind :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep k2trAppKind=TypeRep kkind})=TypeRep kkindtypeRepKind(TrFun{})=Typeable * => TypeRep *forall k (a :: k). Typeable a => TypeRep atypeRep@TypetyConKind::TyCon->[SomeTypeRep]->SomeTypeReptyConKind :: TyCon -> [SomeTypeRep] -> SomeTypeReptyConKind(TyConWord#_Word#_Module_TrName_Int#nKindVars#KindRepkindRep)[SomeTypeRep]kindVars=letkindVarsArr::A.ArrayKindBndrSomeTypeRepkindVarsArr :: Array Int SomeTypeRepkindVarsArr=(Int, Int) -> [SomeTypeRep] -> Array Int SomeTypeRepforall i e. Ix i => (i, i) -> [e] -> Array i eA.listArray(Int0,Int# -> IntI#(Int#nKindVars#Int# -> Int# -> Int#-#Int#1#))[SomeTypeRep]kindVarsinArray Int SomeTypeRep -> KindRep -> SomeTypeRepinstantiateKindRepArray Int SomeTypeRepkindVarsArrKindRepkindRepinstantiateKindRep::A.ArrayKindBndrSomeTypeRep->KindRep->SomeTypeRepinstantiateKindRep :: Array Int SomeTypeRep -> KindRep -> SomeTypeRepinstantiateKindRepArray Int SomeTypeRepvars=KindRep -> SomeTypeRepgowherego::KindRep->SomeTypeRepgo :: KindRep -> SomeTypeRepgo(KindRepTyConAppTyContc[KindRep]args)=letn_kind_args :: Intn_kind_args=TyCon -> InttyConKindArgsTyContc([KindRep]kind_args,[KindRep]ty_args)=Int -> [KindRep] -> ([KindRep], [KindRep])forall a. Int -> [a] -> ([a], [a])splitAtIntn_kind_args[KindRep]args-- First instantiate tycon kind argumentstycon_app :: SomeTypeReptycon_app=TypeRep Any -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep Any -> SomeTypeRep) -> TypeRep Any -> SomeTypeRepforall a b. (a -> b) -> a -> b$TyCon -> [SomeTypeRep] -> TypeRep Anyforall k (a :: k). TyCon -> [SomeTypeRep] -> TypeRep amkTrConTyContc((KindRep -> SomeTypeRep) -> [KindRep] -> [SomeTypeRep]forall a b. (a -> b) -> [a] -> [b]mapKindRep -> SomeTypeRepgo[KindRep]kind_args)-- Then apply remaining type argumentsapplyTy::SomeTypeRep->KindRep->SomeTypeRepapplyTy :: SomeTypeRep -> KindRep -> SomeTypeRepapplyTy(SomeTypeRepTypeRep aacc)KindRepty|SomeTypeRepTypeRep aty'<-KindRep -> SomeTypeRepgoKindRepty=TypeRep (Any a) -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep (Any a) -> SomeTypeRep) -> TypeRep (Any a) -> SomeTypeRepforall a b. (a -> b) -> a -> b$TypeRep Any -> TypeRep a -> TypeRep (Any a)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrApp(TypeRep a -> TypeRep Anyforall a b. a -> bunsafeCoerceTypeRep aacc)TypeRep aty'in(SomeTypeRep -> KindRep -> SomeTypeRep)-> SomeTypeRep -> [KindRep] -> SomeTypeRepforall a b. (b -> a -> b) -> b -> [a] -> bfoldl'SomeTypeRep -> KindRep -> SomeTypeRepapplyTySomeTypeReptycon_app[KindRep]ty_argsgo(KindRepVarIntvar)=Array Int SomeTypeRepvarsArray Int SomeTypeRep -> Int -> SomeTypeRepforall i e. Ix i => Array i e -> i -> eA.!Intvargo(KindRepAppKindRepfKindRepa)=TypeRep (Any Any) -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep (Any Any) -> SomeTypeRep)-> TypeRep (Any Any) -> SomeTypeRepforall a b. (a -> b) -> a -> b$TypeRep Any -> TypeRep Any -> TypeRep (Any Any)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrApp(SomeTypeRep -> TypeRep Anyforall k (a :: k). SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRep -> TypeRep Any) -> SomeTypeRep -> TypeRep Anyforall a b. (a -> b) -> a -> b$KindRep -> SomeTypeRepgoKindRepf)(SomeTypeRep -> TypeRep Anyforall k (a :: k). SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRep -> TypeRep Any) -> SomeTypeRep -> TypeRep Anyforall a b. (a -> b) -> a -> b$KindRep -> SomeTypeRepgoKindRepa)go(KindRepFunKindRepaKindRepb)=TypeRep (Any -> Any) -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep (Any -> Any) -> SomeTypeRep)-> TypeRep (Any -> Any) -> SomeTypeRepforall a b. (a -> b) -> a -> b$TypeRep Any -> TypeRep Any -> TypeRep (Any -> Any)forall a b. TypeRep a -> TypeRep b -> TypeRep (a -> b)mkTrFun(SomeTypeRep -> TypeRep Anyforall k (a :: k). SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRep -> TypeRep Any) -> SomeTypeRep -> TypeRep Anyforall a b. (a -> b) -> a -> b$KindRep -> SomeTypeRepgoKindRepa)(SomeTypeRep -> TypeRep Anyforall k (a :: k). SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRep -> TypeRep Any) -> SomeTypeRep -> TypeRep Anyforall a b. (a -> b) -> a -> b$KindRep -> SomeTypeRepgoKindRepb)go(KindRepTYPERuntimeRepLiftedRep)=TypeRep * -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep *TrTypego(KindRepTYPERuntimeRepr)=SomeKindedTypeRep * -> SomeTypeRepforall k. SomeKindedTypeRep k -> SomeTypeRepunkindedTypeRep(SomeKindedTypeRep * -> SomeTypeRep)-> SomeKindedTypeRep * -> SomeTypeRepforall a b. (a -> b) -> a -> b$SomeKindedTypeRep (RuntimeRep -> *)tYPESomeKindedTypeRep (RuntimeRep -> *)-> SomeKindedTypeRep RuntimeRep -> SomeKindedTypeRep *forall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`RuntimeRep -> SomeKindedTypeRep RuntimeRepruntimeRepTypeRepRuntimeReprgo(KindRepTypeLitSTypeLitSortsortAddr#s)=TypeLitSort -> String -> SomeTypeRepmkTypeLitFromStringTypeLitSortsort(Addr# -> StringunpackCStringUtf8#Addr#s)go(KindRepTypeLitDTypeLitSortsortStrings)=TypeLitSort -> String -> SomeTypeRepmkTypeLitFromStringTypeLitSortsortStringstYPE :: SomeKindedTypeRep (RuntimeRep -> *)tYPE=Typeable TYPE => SomeKindedTypeRep (RuntimeRep -> *)forall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@(RuntimeRep->Type)@TYPEunsafeCoerceRep::SomeTypeRep->TypeRepaunsafeCoerceRep :: SomeTypeRep -> TypeRep aunsafeCoerceRep(SomeTypeRepTypeRep ar)=TypeRep a -> TypeRep aforall a b. a -> bunsafeCoerceTypeRep arunkindedTypeRep::SomeKindedTypeRepk->SomeTypeRepunkindedTypeRep :: SomeKindedTypeRep k -> SomeTypeRepunkindedTypeRep(SomeKindedTypeRepTypeRep ax)=TypeRep a -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep axdataSomeKindedTypeRepkwhereSomeKindedTypeRep::forallk(a::k).TypeRepa->SomeKindedTypeRepkkApp::SomeKindedTypeRep(k->k')->SomeKindedTypeRepk->SomeKindedTypeRepk'kApp :: SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'kApp(SomeKindedTypeRepTypeRep af)(SomeKindedTypeRepTypeRep aa)=TypeRep (a a) -> SomeKindedTypeRep k'forall k (a :: k). TypeRep a -> SomeKindedTypeRep kSomeKindedTypeRep(TypeRep a -> TypeRep a -> TypeRep (a a)forall k1 k2 (a :: k1 -> k2) (b :: k1).TypeRep a -> TypeRep b -> TypeRep (a b)mkTrAppTypeRep afTypeRep aa)kindedTypeRep::forallk(a::k).Typeablea=>SomeKindedTypeRepkkindedTypeRep :: SomeKindedTypeRep kkindedTypeRep=TypeRep a -> SomeKindedTypeRep kforall k (a :: k). TypeRep a -> SomeKindedTypeRep kSomeKindedTypeRep(Typeable a => TypeRep aforall k (a :: k). Typeable a => TypeRep atypeRep@a)buildList::forallk.Typeablek=>[SomeKindedTypeRepk]->SomeKindedTypeRep[k]buildList :: [SomeKindedTypeRep k] -> SomeKindedTypeRep [k]buildList=(SomeKindedTypeRep k -> SomeKindedTypeRep [k] -> SomeKindedTypeRep [k])-> SomeKindedTypeRep [k]-> [SomeKindedTypeRep k]-> SomeKindedTypeRep [k]forall a b. (a -> b -> b) -> b -> [a] -> bfoldrSomeKindedTypeRep k-> SomeKindedTypeRep [k] -> SomeKindedTypeRep [k]forall k.Typeable k =>SomeKindedTypeRep k-> SomeKindedTypeRep [k] -> SomeKindedTypeRep [k]consSomeKindedTypeRep [k]nilwherenil :: SomeKindedTypeRep [k]nil=Typeable '[] => SomeKindedTypeRep [k]forall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@[k]@'[]cons :: SomeKindedTypeRep k-> SomeKindedTypeRep [k] -> SomeKindedTypeRep [k]consSomeKindedTypeRep kxSomeKindedTypeRep [k]rest=TypeRep (':) -> SomeKindedTypeRep (k -> [k] -> [k])forall k (a :: k). TypeRep a -> SomeKindedTypeRep kSomeKindedTypeRep(Typeable (':) => TypeRep (':)forall k (a :: k). Typeable a => TypeRep atypeRep@'(:))SomeKindedTypeRep (k -> [k] -> [k])-> SomeKindedTypeRep k -> SomeKindedTypeRep ([k] -> [k])forall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`SomeKindedTypeRep kxSomeKindedTypeRep ([k] -> [k])-> SomeKindedTypeRep [k] -> SomeKindedTypeRep [k]forall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`SomeKindedTypeRep [k]restruntimeRepTypeRep::RuntimeRep->SomeKindedTypeRepRuntimeRepruntimeRepTypeRep :: RuntimeRep -> SomeKindedTypeRep RuntimeRepruntimeRepTypeRepRuntimeRepr=caseRuntimeReprofRuntimeRepLiftedRep->Typeable 'LiftedRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'LiftedRepRuntimeRepUnliftedRep->Typeable 'UnliftedRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'UnliftedRepVecRepVecCountcVecEleme->Typeable 'VecRep =>SomeKindedTypeRep (VecCount -> VecElem -> RuntimeRep)forall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@_@'VecRepSomeKindedTypeRep (VecCount -> VecElem -> RuntimeRep)-> SomeKindedTypeRep VecCount-> SomeKindedTypeRep (VecElem -> RuntimeRep)forall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`VecCount -> SomeKindedTypeRep VecCountvecCountTypeRepVecCountcSomeKindedTypeRep (VecElem -> RuntimeRep)-> SomeKindedTypeRep VecElem -> SomeKindedTypeRep RuntimeRepforall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`VecElem -> SomeKindedTypeRep VecElemvecElemTypeRepVecElemeTupleRep[RuntimeRep]rs->Typeable 'TupleRep =>SomeKindedTypeRep ([RuntimeRep] -> RuntimeRep)forall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@_@'TupleRepSomeKindedTypeRep ([RuntimeRep] -> RuntimeRep)-> SomeKindedTypeRep [RuntimeRep] -> SomeKindedTypeRep RuntimeRepforall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`[SomeKindedTypeRep RuntimeRep] -> SomeKindedTypeRep [RuntimeRep]forall k.Typeable k =>[SomeKindedTypeRep k] -> SomeKindedTypeRep [k]buildList((RuntimeRep -> SomeKindedTypeRep RuntimeRep)-> [RuntimeRep] -> [SomeKindedTypeRep RuntimeRep]forall a b. (a -> b) -> [a] -> [b]mapRuntimeRep -> SomeKindedTypeRep RuntimeRepruntimeRepTypeRep[RuntimeRep]rs)SumRep[RuntimeRep]rs->Typeable 'SumRep => SomeKindedTypeRep ([RuntimeRep] -> RuntimeRep)forall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@_@'SumRepSomeKindedTypeRep ([RuntimeRep] -> RuntimeRep)-> SomeKindedTypeRep [RuntimeRep] -> SomeKindedTypeRep RuntimeRepforall k k'.SomeKindedTypeRep (k -> k')-> SomeKindedTypeRep k -> SomeKindedTypeRep k'`kApp`[SomeKindedTypeRep RuntimeRep] -> SomeKindedTypeRep [RuntimeRep]forall k.Typeable k =>[SomeKindedTypeRep k] -> SomeKindedTypeRep [k]buildList((RuntimeRep -> SomeKindedTypeRep RuntimeRep)-> [RuntimeRep] -> [SomeKindedTypeRep RuntimeRep]forall a b. (a -> b) -> [a] -> [b]mapRuntimeRep -> SomeKindedTypeRep RuntimeRepruntimeRepTypeRep[RuntimeRep]rs)RuntimeRepIntRep->Typeable 'IntRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'IntRepRuntimeRepInt8Rep->Typeable 'Int8Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Int8RepRuntimeRepInt16Rep->Typeable 'Int16Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Int16RepRuntimeRepInt32Rep->Typeable 'Int32Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Int32RepRuntimeRepInt64Rep->Typeable 'Int64Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Int64RepRuntimeRepWordRep->Typeable 'WordRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'WordRepRuntimeRepWord8Rep->Typeable 'Word8Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Word8RepRuntimeRepWord16Rep->Typeable 'Word16Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Word16RepRuntimeRepWord32Rep->Typeable 'Word32Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Word32RepRuntimeRepWord64Rep->Typeable 'Word64Rep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'Word64RepRuntimeRepAddrRep->Typeable 'AddrRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'AddrRepRuntimeRepFloatRep->Typeable 'FloatRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'FloatRepRuntimeRepDoubleRep->Typeable 'DoubleRep => SomeKindedTypeRep RuntimeRepTypeable 'LiftedRep => SomeKindedTypeRep RuntimeReprep@'DoubleRepwhererep::forall(a::RuntimeRep).Typeablea=>SomeKindedTypeRepRuntimeReprep :: SomeKindedTypeRep RuntimeReprep=Typeable a => SomeKindedTypeRep RuntimeRepforall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@RuntimeRep@avecCountTypeRep::VecCount->SomeKindedTypeRepVecCountvecCountTypeRep :: VecCount -> SomeKindedTypeRep VecCountvecCountTypeRepVecCountc=caseVecCountcofVecCountVec2->Typeable 'Vec2 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec2VecCountVec4->Typeable 'Vec4 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec4VecCountVec8->Typeable 'Vec8 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec8VecCountVec16->Typeable 'Vec16 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec16VecCountVec32->Typeable 'Vec32 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec32VecCountVec64->Typeable 'Vec64 => SomeKindedTypeRep VecCountforall (a :: VecCount). Typeable a => SomeKindedTypeRep VecCountrep@'Vec64whererep::forall(a::VecCount).Typeablea=>SomeKindedTypeRepVecCountrep :: SomeKindedTypeRep VecCountrep=Typeable a => SomeKindedTypeRep VecCountforall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@VecCount@avecElemTypeRep::VecElem->SomeKindedTypeRepVecElemvecElemTypeRep :: VecElem -> SomeKindedTypeRep VecElemvecElemTypeRepVecEleme=caseVecElemeofVecElemInt8ElemRep->Typeable 'Int8ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Int8ElemRepVecElemInt16ElemRep->Typeable 'Int16ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Int16ElemRepVecElemInt32ElemRep->Typeable 'Int32ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Int32ElemRepVecElemInt64ElemRep->Typeable 'Int64ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Int64ElemRepVecElemWord8ElemRep->Typeable 'Word8ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Word8ElemRepVecElemWord16ElemRep->Typeable 'Word16ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Word16ElemRepVecElemWord32ElemRep->Typeable 'Word32ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Word32ElemRepVecElemWord64ElemRep->Typeable 'Word64ElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'Word64ElemRepVecElemFloatElemRep->Typeable 'FloatElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'FloatElemRepVecElemDoubleElemRep->Typeable 'DoubleElemRep => SomeKindedTypeRep VecElemforall (a :: VecElem). Typeable a => SomeKindedTypeRep VecElemrep@'DoubleElemRepwhererep::forall(a::VecElem).Typeablea=>SomeKindedTypeRepVecElemrep :: SomeKindedTypeRep VecElemrep=Typeable a => SomeKindedTypeRep VecElemforall k (a :: k). Typeable a => SomeKindedTypeRep kkindedTypeRep@VecElem@abareArrow::forall(r1::RuntimeRep)(r2::RuntimeRep)(a::TYPEr1)(b::TYPEr2).()=>TypeRep(a->b)->TypeRep((->)::TYPEr1->TYPEr2->Type)bareArrow :: TypeRep (a -> b) -> TypeRep (->)bareArrow(TrFunFingerprint_TypeRep aaTypeRep bb)=TyCon -> [SomeTypeRep] -> TypeRep (->)forall k (a :: k). TyCon -> [SomeTypeRep] -> TypeRep amkTrConTyConfunTyCon[TypeRep r1 -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep r1rep1,TypeRep r2 -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep r2rep2]whererep1 :: TypeRep r1rep1=TypeRep (TYPE r1) -> TypeRep r1TypeRep * -> TypeRep 'LiftedRepgetRuntimeRep(TypeRep (TYPE r1) -> TypeRep r1)-> TypeRep (TYPE r1) -> TypeRep r1forall a b. (a -> b) -> a -> b$TypeRep a -> TypeRep (TYPE r1)forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep aa::TypeRepr1rep2 :: TypeRep r2rep2=TypeRep (TYPE r2) -> TypeRep r2TypeRep * -> TypeRep 'LiftedRepgetRuntimeRep(TypeRep (TYPE r2) -> TypeRep r2)-> TypeRep (TYPE r2) -> TypeRep r2forall a b. (a -> b) -> a -> b$TypeRep b -> TypeRep (TYPE r2)forall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep bb::TypeRepr2bareArrowTypeRep (a -> b)_=String -> TypeRep (->)forall a. HasCallStack => String -> aerrorString"Data.Typeable.Internal.bareArrow: impossible"dataIsTYPE(a::Type)whereIsTYPE::forall(r::RuntimeRep).TypeRepr->IsTYPE(TYPEr)-- | Is a type of the form @TYPE rep@?isTYPE::TypeRep(a::Type)->Maybe(IsTYPEa)isTYPE :: TypeRep a -> Maybe (IsTYPE a)isTYPETypeRep aTrType=IsTYPE * -> Maybe (IsTYPE *)forall a. a -> Maybe aJust(TypeRep 'LiftedRep -> IsTYPE *TypeRep 'LiftedRep -> IsTYPE *IsTYPETypeRep 'LiftedReptrLiftedRep)isTYPE(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep af,trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep br})|Justa :~~: TYPEHRefl<-TypeRep afTypeRep a -> TypeRep TYPE -> Maybe (a :~~: TYPE)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`Typeable TYPE => TypeRep TYPEforall k (a :: k). Typeable a => TypeRep atypeRep@TYPE=IsTYPE (TYPE b) -> Maybe (IsTYPE (TYPE b))forall a. a -> Maybe aJust(TypeRep b -> IsTYPE (TYPE b)TypeRep 'LiftedRep -> IsTYPE *IsTYPETypeRep bTypeRep br)isTYPETypeRep a_=Maybe (IsTYPE a)forall a. Maybe aNothinggetRuntimeRep::forall(r::RuntimeRep).TypeRep(TYPEr)->TypeReprgetRuntimeRep :: TypeRep (TYPE r) -> TypeRep rgetRuntimeRepTypeRep (TYPE r)TrType=TypeRep rTypeRep 'LiftedReptrLiftedRepgetRuntimeRep(TrApp{trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep br})=TypeRep bTypeRep rrgetRuntimeRepTypeRep (TYPE r)_=String -> TypeRep rforall a. HasCallStack => String -> aerrorString"Data.Typeable.Internal.getRuntimeRep: impossible"----------------------------------------------------------------- The Typeable class and friends----------------------------------------------------------------- | The class 'Typeable' allows a concrete representation of a type to-- be calculated.classTypeable(a::k)wheretypeRep#::TypeRepatypeRep::Typeablea=>TypeRepatypeRep :: TypeRep atypeRep=TypeRep aforall k (a :: k). Typeable a => TypeRep atypeRep#typeOf::Typeablea=>a->TypeRepatypeOf :: a -> TypeRep atypeOfa_=TypeRep aforall k (a :: k). Typeable a => TypeRep atypeRep-- | Takes a value of type @a@ and returns a concrete representation-- of that type.---- @since 4.7.0.0someTypeRep::forallproxya.Typeablea=>proxya->SomeTypeRepsomeTypeRep :: proxy a -> SomeTypeRepsomeTypeRepproxy a_=TypeRep a -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep aforall k (a :: k). Typeable a => TypeRep atypeRep::TypeRepa){-# INLINEtypeRep#-}someTypeRepFingerprint::SomeTypeRep->FingerprintsomeTypeRepFingerprint :: SomeTypeRep -> FingerprintsomeTypeRepFingerprint(SomeTypeRepTypeRep at)=TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep at----------------- Showing TypeReps ---------------------- This follows roughly the precedence structure described in Note [Precedence-- in types].instanceShow(TypeRep(a::k))whereshowsPrec :: Int -> TypeRep a -> String -> StringshowsPrec=Int -> TypeRep a -> String -> Stringforall k (a :: k). Int -> TypeRep a -> String -> StringshowTypeableshowTypeable::Int->TypeRep(a::k)->ShowSshowTypeable :: Int -> TypeRep a -> String -> StringshowTypeableInt_TypeRep aTrType=Char -> String -> StringshowCharChar'*'showTypeableInt_TypeRep arep|TyCon -> BoolisListTyConTyContc,[SomeTypeRepty]<-[SomeTypeRep]tys=Char -> String -> StringshowCharChar'['(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.SomeTypeRep -> String -> Stringforall a. Show a => a -> String -> StringshowsSomeTypeRepty(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Char -> String -> StringshowCharChar']'-- Take care only to render saturated tuple tycon applications-- with tuple notation (#14341).|TyCon -> BoolisTupleTyConTyContc,Just* :~~: k_<-TypeRep *TrTypeTypeRep * -> TypeRep k -> Maybe (* :~~: k)forall k1 k2 (a :: k1) (b :: k2).TypeRep a -> TypeRep b -> Maybe (a :~~: b)`eqTypeRep`TypeRep a -> TypeRep kforall k (a :: k). TypeRep a -> TypeRep ktypeRepKindTypeRep arep=Char -> String -> StringshowCharChar'('(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.(String -> String) -> [SomeTypeRep] -> String -> Stringforall a. Show a => (String -> String) -> [a] -> String -> StringshowArgs(Char -> String -> StringshowCharChar',')[SomeTypeRep]tys(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Char -> String -> StringshowCharChar')'where(TyContc,[SomeTypeRep]tys)=TypeRep a -> (TyCon, [SomeTypeRep])forall k (a :: k). TypeRep a -> (TyCon, [SomeTypeRep])splitAppsTypeRep arepshowTypeableInt_(TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyContycon,trKindVars :: forall k (a :: k). TypeRep a -> [SomeTypeRep]trKindVars=[]})=TyCon -> String -> StringshowTyConTyContyconshowTypeableIntp(TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyContycon,trKindVars :: forall k (a :: k). TypeRep a -> [SomeTypeRep]trKindVars=[SomeTypeRep]args})=Bool -> (String -> String) -> String -> StringshowParen(IntpInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>Int9)((String -> String) -> String -> String)-> (String -> String) -> String -> Stringforall a b. (a -> b) -> a -> b$TyCon -> String -> StringshowTyConTyContycon(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Char -> String -> StringshowCharChar' '(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.(String -> String) -> [SomeTypeRep] -> String -> Stringforall a. Show a => (String -> String) -> [a] -> String -> StringshowArgs(Char -> String -> StringshowCharChar' ')[SomeTypeRep]argsshowTypeableIntp(TrFun{trFunArg :: forall a b. TypeRep (a -> b) -> TypeRep atrFunArg=TypeRep ax,trFunRes :: forall a b. TypeRep (a -> b) -> TypeRep btrFunRes=TypeRep br})=Bool -> (String -> String) -> String -> StringshowParen(IntpInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>Int8)((String -> String) -> String -> String)-> (String -> String) -> String -> Stringforall a b. (a -> b) -> a -> b$Int -> TypeRep a -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt9TypeRep ax(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.String -> String -> StringshowStringString" -> "(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Int -> TypeRep b -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt8TypeRep brshowTypeableIntp(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep af,trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep bx})=Bool -> (String -> String) -> String -> StringshowParen(IntpInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>Int9)((String -> String) -> String -> String)-> (String -> String) -> String -> Stringforall a b. (a -> b) -> a -> b$Int -> TypeRep a -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt8TypeRep af(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Char -> String -> StringshowCharChar' '(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.Int -> TypeRep b -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt10TypeRep bx-- | @since 4.10.0.0instanceShowSomeTypeRepwhereshowsPrec :: Int -> SomeTypeRep -> String -> StringshowsPrecIntp(SomeTypeRepTypeRep aty)=Int -> TypeRep a -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecIntpTypeRep atysplitApps::TypeRepa->(TyCon,[SomeTypeRep])splitApps :: TypeRep a -> (TyCon, [SomeTypeRep])splitApps=[SomeTypeRep] -> TypeRep a -> (TyCon, [SomeTypeRep])forall k (a :: k).[SomeTypeRep] -> TypeRep a -> (TyCon, [SomeTypeRep])go[]wherego::[SomeTypeRep]->TypeRepa->(TyCon,[SomeTypeRep])go :: [SomeTypeRep] -> TypeRep a -> (TyCon, [SomeTypeRep])go[SomeTypeRep]xs(TrTyCon{trTyCon :: forall k (a :: k). TypeRep a -> TyContrTyCon=TyContc})=(TyContc,[SomeTypeRep]xs)go[SomeTypeRep]xs(TrApp{trAppFun :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep atrAppFun=TypeRep af,trAppArg :: forall k2 k1 (a :: k1 -> k2) (b :: k1). TypeRep (a b) -> TypeRep btrAppArg=TypeRep bx})=[SomeTypeRep] -> TypeRep a -> (TyCon, [SomeTypeRep])forall k (a :: k).[SomeTypeRep] -> TypeRep a -> (TyCon, [SomeTypeRep])go(TypeRep b -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep bxSomeTypeRep -> [SomeTypeRep] -> [SomeTypeRep]forall a. a -> [a] -> [a]:[SomeTypeRep]xs)TypeRep afgo[](TrFun{trFunArg :: forall a b. TypeRep (a -> b) -> TypeRep atrFunArg=TypeRep aa,trFunRes :: forall a b. TypeRep (a -> b) -> TypeRep btrFunRes=TypeRep bb})=(TyConfunTyCon,[TypeRep a -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep aa,TypeRep b -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep bb])go[SomeTypeRep]_(TrFun{})=String -> (TyCon, [SomeTypeRep])forall a. String -> aerrorWithoutStackTraceString"Data.Typeable.Internal.splitApps: Impossible 1"go[]TypeRep aTrType=(TyContyConTYPE,[TypeRep 'LiftedRep -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRepTypeRep 'LiftedReptrLiftedRep])go[SomeTypeRep]_TypeRep aTrType=String -> (TyCon, [SomeTypeRep])forall a. String -> aerrorWithoutStackTraceString"Data.Typeable.Internal.splitApps: Impossible 2"-- This is incredibly shady! We don't really want to do this here; we-- should really have the compiler reveal the TYPE TyCon directly-- somehow. We need to construct this by hand because otherwise-- we end up with horrible and somewhat mysterious loops trying to calculate-- typeRep @TYPE. For the moment, we use the fact that we can get the proper-- name of the ghc-prim package from the TyCon of LiftedRep (which we can-- produce a TypeRep for without difficulty), and then just substitute in the-- appropriate module and constructor names.---- The ticket to find a better way to deal with this is-- #14480.tyConTYPE::TyContyConTYPE :: TyContyConTYPE=String -> String -> String -> Int -> KindRep -> TyConmkTyCon(TyCon -> StringtyConPackageTyConliftedRepTyCon)String"GHC.Prim"String"TYPE"Int0(KindRep -> KindRep -> KindRepKindRepFun(TyCon -> [KindRep] -> KindRepKindRepTyConAppTyConliftedRepTyCon[])(RuntimeRep -> KindRepKindRepTYPERuntimeRepLiftedRep))whereliftedRepTyCon :: TyConliftedRepTyCon=TypeRep RuntimeRep -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(Typeable RuntimeRep => TypeRep RuntimeRepforall k (a :: k). Typeable a => TypeRep atypeRep@RuntimeRep)funTyCon::TyConfunTyCon :: TyConfunTyCon=TypeRep (->) -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(Typeable (->) => TypeRep (->)forall k (a :: k). Typeable a => TypeRep atypeRep@(->))isListTyCon::TyCon->BoolisListTyCon :: TyCon -> BoolisListTyConTyContc=TyContcTyCon -> TyCon -> Boolforall a. Eq a => a -> a -> Bool==TypeRep [] -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(TypeRep []forall k (a :: k). Typeable a => TypeRep atypeRep::TypeRep[])isTupleTyCon::TyCon->BoolisTupleTyCon :: TyCon -> BoolisTupleTyConTyContc|(Char'(':Char',':String_)<-TyCon -> StringtyConNameTyContc=BoolTrue|Boolotherwise=BoolFalse-- This is only an approximation. We don't have the general-- character-classification machinery here, so we just do our best.-- This should work for promoted Haskell 98 data constructors and-- for TypeOperators type constructors that begin with ASCII-- characters, but it will miss Unicode operators.---- If we wanted to catch Unicode as well, we ought to consider moving-- GHC.Lexeme from ghc-boot-th to base. Then we could just say:---- startsVarSym symb || startsConSym symb---- But this is a fair deal of work just for one corner case, so I think I'll-- leave it like this unless someone shouts.isOperatorTyCon::TyCon->BoolisOperatorTyCon :: TyCon -> BoolisOperatorTyConTyContc|Charsymb:String_<-TyCon -> StringtyConNameTyContc,CharsymbChar -> String -> Boolforall a. Eq a => a -> [a] -> Bool`elem`String"!#$%&*+./<=>?@\\^|-~:"=BoolTrue|Boolotherwise=BoolFalseshowTyCon::TyCon->ShowSshowTyCon :: TyCon -> String -> StringshowTyConTyContycon=Bool -> (String -> String) -> String -> StringshowParen(TyCon -> BoolisOperatorTyConTyContycon)(TyCon -> String -> Stringforall a. Show a => a -> String -> StringshowsTyContycon)showArgs::Showa=>ShowS->[a]->ShowSshowArgs :: (String -> String) -> [a] -> String -> StringshowArgsString -> String_[]=String -> Stringforall a. a -> aidshowArgsString -> String_[aa]=Int -> a -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt10aashowArgsString -> Stringsep(aa:[a]as)=Int -> a -> String -> Stringforall a. Show a => Int -> a -> String -> StringshowsPrecInt10aa(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.String -> Stringsep(String -> String) -> (String -> String) -> String -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.(String -> String) -> [a] -> String -> Stringforall a. Show a => (String -> String) -> [a] -> String -> StringshowArgsString -> Stringsep[a]as-- | Helper to fully evaluate 'TypeRep' for use as @NFData(rnf)@ implementation---- @since 4.8.0.0rnfTypeRep::TypeRepa->()-- The TypeRep structure is almost entirely strict by definition. The-- fingerprinting and strict kind caching ensure that everything-- else is forced anyway. So we don't need to do anything special-- to reduce to normal form.rnfTypeRep :: TypeRep a -> ()rnfTypeRep!TypeRep a_=()-- | Helper to fully evaluate 'SomeTypeRep' for use as @NFData(rnf)@-- implementation---- @since 4.10.0.0rnfSomeTypeRep::SomeTypeRep->()rnfSomeTypeRep :: SomeTypeRep -> ()rnfSomeTypeRep(SomeTypeRepTypeRep ar)=TypeRep a -> ()forall k (a :: k). TypeRep a -> ()rnfTypeRepTypeRep ar{- ********************************************************** ** TyCon/TypeRep definitions for type literals ** (Symbol and Nat) ** ********************************************************** -}patternKindRepTypeLit::TypeLitSort->String->KindReppattern$bKindRepTypeLit :: TypeLitSort -> String -> KindRep$mKindRepTypeLit :: forall r.KindRep -> (TypeLitSort -> String -> r) -> (Void# -> r) -> rKindRepTypeLitsortt<-(getKindRepTypeLit->Just(sort,t))whereKindRepTypeLitTypeLitSortsortStringt=TypeLitSort -> String -> KindRepKindRepTypeLitDTypeLitSortsortStringt{-# COMPLETEKindRepTyConApp,KindRepVar,KindRepApp,KindRepFun,KindRepTYPE,KindRepTypeLit#-}getKindRepTypeLit::KindRep->Maybe(TypeLitSort,String)getKindRepTypeLit :: KindRep -> Maybe (TypeLitSort, String)getKindRepTypeLit(KindRepTypeLitSTypeLitSortsortAddr#t)=(TypeLitSort, String) -> Maybe (TypeLitSort, String)forall a. a -> Maybe aJust(TypeLitSortsort,Addr# -> StringunpackCStringUtf8#Addr#t)getKindRepTypeLit(KindRepTypeLitDTypeLitSortsortStringt)=(TypeLitSort, String) -> Maybe (TypeLitSort, String)forall a. a -> Maybe aJust(TypeLitSortsort,Stringt)getKindRepTypeLitKindRep_=Maybe (TypeLitSort, String)forall a. Maybe aNothing-- | Exquisitely unsafe.mkTyCon#::Addr#-- ^ package name->Addr#-- ^ module name->Addr#-- ^ the name of the type constructor->Int#-- ^ number of kind variables->KindRep-- ^ kind representation->TyCon-- ^ A unique 'TyCon' objectmkTyCon# :: Addr# -> Addr# -> Addr# -> Int# -> KindRep -> TyConmkTyCon#Addr#pkgAddr#modlAddr#nameInt#n_kindsKindRepkind_rep|Fingerprint(W64#Word#hi)(W64#Word#lo)<-Fingerprintfingerprint=Word# -> Word# -> Module -> TrName -> Int# -> KindRep -> TyConTyConWord#hiWord#loModulemod(Addr# -> TrNameTrNameSAddr#name)Int#n_kindsKindRepkind_repwheremod :: Modulemod=TrName -> TrName -> ModuleModule(Addr# -> TrNameTrNameSAddr#pkg)(Addr# -> TrNameTrNameSAddr#modl)fingerprint::Fingerprintfingerprint :: Fingerprintfingerprint=String -> String -> String -> FingerprintmkTyConFingerprint(Addr# -> StringunpackCStringUtf8#Addr#pkg)(Addr# -> StringunpackCStringUtf8#Addr#modl)(Addr# -> StringunpackCStringUtf8#Addr#name)-- it is extremely important that this fingerprint computation-- remains in sync with that in TcTypeable to ensure that type-- equality is correct.-- | Exquisitely unsafe.mkTyCon::String-- ^ package name->String-- ^ module name->String-- ^ the name of the type constructor->Int-- ^ number of kind variables->KindRep-- ^ kind representation->TyCon-- ^ A unique 'TyCon' object-- Used when the strings are dynamically allocated,-- eg from binary deserialisationmkTyCon :: String -> String -> String -> Int -> KindRep -> TyConmkTyConStringpkgStringmodlStringname(I#Int#n_kinds)KindRepkind_rep|Fingerprint(W64#Word#hi)(W64#Word#lo)<-Fingerprintfingerprint=Word# -> Word# -> Module -> TrName -> Int# -> KindRep -> TyConTyConWord#hiWord#loModulemod(String -> TrNameTrNameDStringname)Int#n_kindsKindRepkind_repwheremod :: Modulemod=TrName -> TrName -> ModuleModule(String -> TrNameTrNameDStringpkg)(String -> TrNameTrNameDStringmodl)fingerprint::Fingerprintfingerprint :: Fingerprintfingerprint=String -> String -> String -> FingerprintmkTyConFingerprintStringpkgStringmodlStringname-- This must match the computation done in TcTypeable.mkTyConRepTyConRHS.mkTyConFingerprint::String-- ^ package name->String-- ^ module name->String-- ^ tycon name->FingerprintmkTyConFingerprint :: String -> String -> String -> FingerprintmkTyConFingerprintStringpkg_nameStringmod_nameStringtycon_name=[Fingerprint] -> FingerprintfingerprintFingerprints[String -> FingerprintfingerprintStringStringpkg_name,String -> FingerprintfingerprintStringStringmod_name,String -> FingerprintfingerprintStringStringtycon_name]mkTypeLitTyCon::String->TyCon->TyConmkTypeLitTyCon :: String -> TyCon -> TyConmkTypeLitTyConStringnameTyConkind_tycon=String -> String -> String -> Int -> KindRep -> TyConmkTyConString"base"String"GHC.TypeLits"StringnameInt0KindRepkindwherekind :: KindRepkind=TyCon -> [KindRep] -> KindRepKindRepTyConAppTyConkind_tycon[]-- | Used to make `'Typeable' instance for things of kind NattypeNatTypeRep::KnownNata=>Proxy#a->TypeRepatypeNatTypeRep :: Proxy# a -> TypeRep atypeNatTypeRepProxy# ap=String -> TyCon -> TypeRep aforall k (a :: k). Typeable k => String -> TyCon -> TypeRep atypeLitTypeRep(Natural -> Stringforall a. Show a => a -> Stringshow(Proxy# a -> Naturalforall (n :: Nat). KnownNat n => Proxy# n -> NaturalnatVal'Proxy# ap))TyContcNat-- | Used to make `'Typeable' instance for things of kind SymboltypeSymbolTypeRep::KnownSymbola=>Proxy#a->TypeRepatypeSymbolTypeRep :: Proxy# a -> TypeRep atypeSymbolTypeRepProxy# ap=String -> TyCon -> TypeRep aforall k (a :: k). Typeable k => String -> TyCon -> TypeRep atypeLitTypeRep(String -> Stringforall a. Show a => a -> Stringshow(Proxy# a -> Stringforall (n :: Symbol). KnownSymbol n => Proxy# n -> StringsymbolVal'Proxy# ap))TyContcSymbolmkTypeLitFromString::TypeLitSort->String->SomeTypeRepmkTypeLitFromString :: TypeLitSort -> String -> SomeTypeRepmkTypeLitFromStringTypeLitSortTypeLitSymbolStrings=TypeRep Symbol -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep Symbol -> SomeTypeRep) -> TypeRep Symbol -> SomeTypeRepforall a b. (a -> b) -> a -> b$(String -> TyCon -> TypeRep Symbolforall k (a :: k). Typeable k => String -> TyCon -> TypeRep atypeLitTypeRepStringsTyContcSymbol::TypeRepSymbol)mkTypeLitFromStringTypeLitSortTypeLitNatStrings=TypeRep Nat -> SomeTypeRepforall k (a :: k). TypeRep a -> SomeTypeRepSomeTypeRep(TypeRep Nat -> SomeTypeRep) -> TypeRep Nat -> SomeTypeRepforall a b. (a -> b) -> a -> b$(String -> TyCon -> TypeRep Natforall k (a :: k). Typeable k => String -> TyCon -> TypeRep atypeLitTypeRepStringsTyContcSymbol::TypeRepNat)tcSymbol::TyContcSymbol :: TyContcSymbol=TypeRep Symbol -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(Typeable Symbol => TypeRep Symbolforall k (a :: k). Typeable a => TypeRep atypeRep@Symbol)tcNat::TyContcNat :: TyContcNat=TypeRep Nat -> TyConforall k (a :: k). TypeRep a -> TyContypeRepTyCon(Typeable Nat => TypeRep Natforall k (a :: k). Typeable a => TypeRep atypeRep@Nat)-- | An internal function, to make representations for type literals.typeLitTypeRep::forallk(a::k).(Typeablek)=>String->TyCon->TypeRepatypeLitTypeRep :: String -> TyCon -> TypeRep atypeLitTypeRepStringnmTyConkind_tycon=TyCon -> [SomeTypeRep] -> TypeRep aforall k (a :: k). TyCon -> [SomeTypeRep] -> TypeRep amkTrCon(String -> TyCon -> TyConmkTypeLitTyConStringnmTyConkind_tycon)[]-- | For compiler use.mkTrFun::forall(r1::RuntimeRep)(r2::RuntimeRep)(a::TYPEr1)(b::TYPEr2).TypeRepa->TypeRepb->TypeRep((a->b)::Type)mkTrFun :: TypeRep a -> TypeRep b -> TypeRep (a -> b)mkTrFunTypeRep aargTypeRep bres=TrFun :: forall a b.Fingerprint -> TypeRep a -> TypeRep b -> TypeRep (a -> b)TrFun{trFunFingerprint :: FingerprinttrFunFingerprint=Fingerprintfpr,trFunArg :: TypeRep atrFunArg=TypeRep aarg,trFunRes :: TypeRep btrFunRes=TypeRep bres}wherefpr :: Fingerprintfpr=[Fingerprint] -> FingerprintfingerprintFingerprints[TypeRep a -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep aarg,TypeRep b -> Fingerprintforall k (a :: k). TypeRep a -> FingerprinttypeRepFingerprintTypeRep bres]{- $kind_instantiationConsider a type like 'Data.Proxy.Proxy',@data Proxy :: forall k. k -> Type@One might think that one could decompose an instantiation of this type like@Proxy Int@ into two applications,@'App' (App a b) c === typeRep @(Proxy Int)@where,@a = typeRep @Proxyb = typeRep @Typec = typeRep @Int@However, this isn't the case. Instead we can only decompose into an applicationand a constructor,@'App' ('Con' proxyTyCon) (typeRep @Int) === typeRep @(Proxy Int)@The reason for this is that 'Typeable' can only represent /kind-monomorphic/types. That is, we must saturate enough of @Proxy@\'s arguments tofully determine its kind. In the particular case of @Proxy@ this means we mustinstantiate the kind variable @k@ such that no @forall@-quantified variablesremain.While it is not possible to decompose the 'Con' above into an application, it ispossible to observe the kind variable instantiations of the constructor with the'Con\'' pattern,@'App' (Con' proxyTyCon kinds) _ === typeRep @(Proxy Int)@Here @kinds@ will be @[typeRep \@Type]@.-}
[8]ページ先頭