{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude
, OverlappingInstances
, ScopedTypeVariables
, FlexibleInstances
, TypeOperators
, PolyKinds
, GADTs
, MagicHash
#-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module Data.Typeable
(
Typeable,
typeRep,
(:~:)(Refl),
typeOf, typeOf1, typeOf2, typeOf3, typeOf4, typeOf5, typeOf6, typeOf7,
Typeable1, Typeable2, Typeable3, Typeable4, Typeable5, Typeable6,
Typeable7,
cast,
eqT,
gcast,
gcast1,
gcast2,
Proxy (..),
TypeRep,
showsTypeRep,
TyCon,
tyConString,
tyConPackage,
tyConModule,
tyConName,
mkTyCon3,
mkTyConApp,
mkAppTy,
mkFunTy,
splitTyConApp,
funResultTy,
typeRepTyCon,
typeRepArgs,
) where
import Data.Typeable.Internal hiding (mkTyCon)
import Data.Type.Equality
import Unsafe.Coerce
import Data.Maybe
import GHC.Base
cast :: forall a b. (Typeable a, Typeable b) => a -> Maybe b
cast x = if typeRep (Proxy :: Proxy a) == typeRep (Proxy :: Proxy b)
then Just $ unsafeCoerce x
else Nothing
eqT :: forall a b. (Typeable a, Typeable b) => Maybe (a :~: b)
eqT = if typeRep (Proxy :: Proxy a) == typeRep (Proxy :: Proxy b)
then Just $ unsafeCoerce Refl
else Nothing
gcast :: forall a b c. (Typeable a, Typeable b) => c a -> Maybe (c b)
gcast x = fmap (\Refl -> x) (eqT :: Maybe (a :~: b))
gcast1 :: forall c t t' a. (Typeable t, Typeable t')
=> c (t a) -> Maybe (c (t' a))
gcast1 x = fmap (\Refl -> x) (eqT :: Maybe (t :~: t'))
gcast2 :: forall c t t' a b. (Typeable t, Typeable t')
=> c (t a b) -> Maybe (c (t' a b))
gcast2 x = fmap (\Refl -> x) (eqT :: Maybe (t :~: t'))