Type.Reflection (original) (raw)
Contents
Description
This provides a type-indexed type representation mechanism, similar to that described by,
- Simon Peyton-Jones, Stephanie Weirich, Richard Eisenberg, Dimitrios Vytiniotis. "A reflection on types."Proc. Philip Wadler's 60th birthday Festschrift, Edinburgh (April 2016). ([PDF](https:/_www.microsoft.com_en-us_research_wp-content_uploads_2016_08_dynamic.pdf))
The interface provides [TypeRep](Type-Reflection.html#t:TypeRep "Type.Reflection")
, a type representation which can be safely decomposed and composed. See Data.Dynamic for an example of this.
Since: 4.10.0.0
Synopsis
- class Typeable (a :: k)
- typeRep :: Typeable a => TypeRep a
- withTypeable :: forall k (a :: k) rep (r :: TYPE rep). TypeRep a -> (Typeable a => r) -> r
- data a :~: b where
- data a :~~: b where
- data TypeRep a
- typeOf :: Typeable a => a -> TypeRep a
- pattern App :: forall k2 (t :: k2). () => forall k1 (a :: k1 -> k2) (b :: k1). t ~ a b => TypeRep a -> TypeRep b -> TypeRep t
- pattern Con :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> TypeRep a
- pattern Con' :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> [SomeTypeRep] -> TypeRep a
- pattern Fun :: forall k (fun :: k). () => forall (r1 :: RuntimeRep) (r2 :: RuntimeRep) (arg :: TYPE r1) (res :: TYPE r2). (k ~ Type, fun ~~ (arg -> res)) => TypeRep arg -> TypeRep res -> TypeRep fun
- typeRepTyCon :: TypeRep a -> TyCon
- rnfTypeRep :: TypeRep a -> ()
- eqTypeRep :: forall k1 k2 (a :: k1) (b :: k2). TypeRep a -> TypeRep b -> Maybe (a :~~: b)
- typeRepKind :: TypeRep (a :: k) -> TypeRep k
- splitApps :: TypeRep a -> (TyCon, [SomeTypeRep])
- data SomeTypeRep where
- SomeTypeRep :: forall k (a :: k). !(TypeRep a) -> SomeTypeRep
- someTypeRep :: forall proxy a. Typeable a => proxy a -> SomeTypeRep
- someTypeRepTyCon :: SomeTypeRep -> TyCon
- rnfSomeTypeRep :: SomeTypeRep -> ()
- data TyCon
- tyConPackage :: TyCon -> String
- tyConModule :: TyCon -> String
- tyConName :: TyCon -> String
- rnfTyCon :: TyCon -> ()
- data Module
- moduleName :: Module -> String
- modulePackage :: Module -> String
- rnfModule :: Module -> ()
class Typeable (a :: k) Source #
The class [Typeable](Type-Reflection.html#t:Typeable "Type.Reflection")
allows a concrete representation of a type to be calculated.
Minimal complete definition
typeRep#
data a :~: b where infix 4 Source #
Propositional equality. If a :~: b
is inhabited by some terminating value, then the type a
is the same as the type b
. To use this equality in practice, pattern-match on the a :~: b
to get out the Refl
constructor; in the body of the pattern-match, the compiler knows that a ~ b
.
Since: 4.7.0.0
data a :~~: b where infix 4 Source #
Kind heterogeneous propositional equality. Like [:~:](Type-Reflection.html#t::-126-: "Type.Reflection")
, a :~~: b
is inhabited by a terminating value if and only if a
is the same type as b
.
Since: 4.10.0.0
Type representationsType-Indexed
A concrete representation of a (monomorphic) type.[TypeRep](Type-Reflection.html#t:TypeRep "Type.Reflection")
supports reasonably efficient equality.
pattern App :: forall k2 (t :: k2). () => forall k1 (a :: k1 -> k2) (b :: k1). t ~ a b => TypeRep a -> TypeRep b -> TypeRep t Source #
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)
.
pattern Con :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> TypeRep a Source #
Pattern match on a type constructor
pattern Con' :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> [SomeTypeRep] -> TypeRep a Source #
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
QuantifiedType constructorsModule names
data Module #
Instances
Instances details