Copyright | (c) The University of Glasgow CWI 2001--2017 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | libraries@haskell.org |
Stability | experimental |
Portability | non-portable (requires GADTs and compiler support) |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
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).
The interface provides TypeRep
, a type representation which can
be safely decomposed and composed. See Data.Dynamic for an example of this.
Since: base-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 :: k1) :~~: (b :: k2) where
- data TypeRep (a :: k)
- 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 -> ()
The Typeable class
The class Typeable
allows a concrete representation of a type to
be calculated.
typeRep#
withTypeable :: forall k (a :: k) rep (r :: TYPE rep). TypeRep a -> (Typeable a => r) -> r #
Propositional equality
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: base-4.7.0.0
Instances
Category ((:~:) :: k -> k -> Type) # | Since: base-4.7.0.0 |
TestEquality ((:~:) a :: k -> Type) # | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
TestCoercion ((:~:) a :: k -> Type) # | Since: base-4.7.0.0 |
Defined in Data.Type.Coercion | |
a ~ b => Bounded (a :~: b) # | Since: base-4.7.0.0 |
a ~ b => Enum (a :~: b) # | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
Eq (a :~: b) # | Since: base-4.7.0.0 |
(a ~ b, Data a) => Data (a :~: b) # | Since: base-4.7.0.0 |
Defined in Data.Data gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> (a :~: b) -> c (a :~: b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (a :~: b) # toConstr :: (a :~: b) -> Constr # dataTypeOf :: (a :~: b) -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (a :~: b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (a :~: b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> (a :~: b) -> a :~: b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> (a :~: b) -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> (a :~: b) -> r # gmapQ :: (forall d. Data d => d -> u) -> (a :~: b) -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> (a :~: b) -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> (a :~: b) -> m (a :~: b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :~: b) -> m (a :~: b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :~: b) -> m (a :~: b) # | |
Ord (a :~: b) # | Since: base-4.7.0.0 |
Defined in Data.Type.Equality | |
a ~ b => Read (a :~: b) # | Since: base-4.7.0.0 |
Show (a :~: b) # | Since: base-4.7.0.0 |
data (a :: k1) :~~: (b :: k2) where infix 4 #
Kind heterogeneous propositional equality. Like :~:
, a :~~: b
is
inhabited by a terminating value if and only if a
is the same type as b
.
Since: base-4.10.0.0
Instances
Category ((:~~:) :: k -> k -> Type) # | Since: base-4.10.0.0 |
TestEquality ((:~~:) a :: k -> Type) # | Since: base-4.10.0.0 |
Defined in Data.Type.Equality | |
TestCoercion ((:~~:) a :: k -> Type) # | Since: base-4.10.0.0 |
Defined in Data.Type.Coercion | |
a ~~ b => Bounded (a :~~: b) # | Since: base-4.10.0.0 |
a ~~ b => Enum (a :~~: b) # | Since: base-4.10.0.0 |
Defined in Data.Type.Equality succ :: (a :~~: b) -> a :~~: b # pred :: (a :~~: b) -> a :~~: b # fromEnum :: (a :~~: b) -> Int # enumFrom :: (a :~~: b) -> [a :~~: b] # enumFromThen :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromTo :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromThenTo :: (a :~~: b) -> (a :~~: b) -> (a :~~: b) -> [a :~~: b] # | |
Eq (a :~~: b) # | Since: base-4.10.0.0 |
(Typeable i, Typeable j, Typeable a, Typeable b, a ~~ b) => Data (a :~~: b) # | Since: base-4.10.0.0 |
Defined in Data.Data gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> (a :~~: b) -> c (a :~~: b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (a :~~: b) # toConstr :: (a :~~: b) -> Constr # dataTypeOf :: (a :~~: b) -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (a :~~: b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (a :~~: b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> (a :~~: b) -> a :~~: b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> (a :~~: b) -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> (a :~~: b) -> r # gmapQ :: (forall d. Data d => d -> u) -> (a :~~: b) -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> (a :~~: b) -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> (a :~~: b) -> m (a :~~: b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :~~: b) -> m (a :~~: b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> (a :~~: b) -> m (a :~~: b) # | |
Ord (a :~~: b) # | Since: base-4.10.0.0 |
Defined in Data.Type.Equality compare :: (a :~~: b) -> (a :~~: b) -> Ordering Source # (<) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (<=) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (>) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (>=) :: (a :~~: b) -> (a :~~: b) -> Bool Source # | |
a ~~ b => Read (a :~~: b) # | Since: base-4.10.0.0 |
Show (a :~~: b) # | Since: base-4.10.0.0 |
Type representations
Type-Indexed
A concrete representation of a (monomorphic) type.
TypeRep
supports reasonably efficient equality.
Instances
TestEquality (TypeRep :: k -> Type) # | |
Defined in Data.Typeable.Internal | |
Eq (TypeRep a) # | Since: base-2.1 |
Ord (TypeRep a) # | Since: base-4.4.0.0 |
Defined in Data.Typeable.Internal | |
Show (TypeRep a) # | |
pattern App :: forall k2 (t :: k2). () => forall k1 (a :: k1 -> k2) (b :: k1). t ~ a b => TypeRep a -> TypeRep b -> TypeRep t #
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 #
Pattern match on a type constructor
pattern Con' :: forall k (a :: k). () => IsApplication a ~ "" => TyCon -> [SomeTypeRep] -> TypeRep a #
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
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 #
The function type constructor.
For instance,
typeRep @(Int -> Char) === Fun (typeRep @Int) (typeRep @Char)
typeRepTyCon :: TypeRep a -> TyCon #
Observe the type constructor of a type representation
rnfTypeRep :: TypeRep a -> () #
Helper to fully evaluate TypeRep
for use as NFData(rnf)
implementation
Since: base-4.8.0.0
eqTypeRep :: forall k1 k2 (a :: k1) (b :: k2). TypeRep a -> TypeRep b -> Maybe (a :~~: b) #
Type equality
Since: base-4.10
typeRepKind :: TypeRep (a :: k) -> TypeRep k #
Observe the kind of a type.
splitApps :: TypeRep a -> (TyCon, [SomeTypeRep]) #
Quantified
data SomeTypeRep where #
A non-indexed type representation.
SomeTypeRep :: forall k (a :: k). !(TypeRep a) -> SomeTypeRep |
Instances
Eq SomeTypeRep # | |
Defined in Data.Typeable.Internal (==) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (/=) :: SomeTypeRep -> SomeTypeRep -> Bool Source # | |
Ord SomeTypeRep # | |
Defined in Data.Typeable.Internal compare :: SomeTypeRep -> SomeTypeRep -> Ordering Source # (<) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (<=) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (>) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (>=) :: SomeTypeRep -> SomeTypeRep -> Bool Source # max :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep Source # min :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep Source # | |
Show SomeTypeRep # | Since: base-4.10.0.0 |
Defined in Data.Typeable.Internal showsPrec :: Int -> SomeTypeRep -> ShowS # show :: SomeTypeRep -> String # showList :: [SomeTypeRep] -> ShowS # |
someTypeRep :: forall proxy a. Typeable a => proxy a -> SomeTypeRep #
Takes a value of type a
and returns a concrete representation
of that type.
Since: base-4.7.0.0
someTypeRepTyCon :: SomeTypeRep -> TyCon #
Observe the type constructor of a quantified type representation.
rnfSomeTypeRep :: SomeTypeRep -> () #
Helper to fully evaluate SomeTypeRep
for use as NFData(rnf)
implementation
Since: base-4.10.0.0
Type constructors
tyConPackage :: TyCon -> String #
tyConModule :: TyCon -> String #
Module names
moduleName :: Module -> String #
modulePackage :: Module -> String #