1. 程式人生 > >Haskell語言學習筆記(81)Data.Typeable

Haskell語言學習筆記(81)Data.Typeable

http https href 筆記 The 動態 tps -type overflow

Data.Typeable

利用 Data.Typeable,可以打印動態類型信息。

class Typeable (a :: k) where
  typeRep# :: TypeRep a

typeRep :: Typeable a => TypeRep a
typeRep = typeRep#

typeOf :: Typeable a => a -> TypeRep a
typeOf _ = typeRep

typeOf 函數可以返回某個值的類型信息。

Prelude> :m +Data.Typeable
Prelude Data.Typeable> :t typeOf 'a'
typeOf 'a' :: TypeRep
Prelude Data.Typeable> typeOf 'a'
Char

How can I read the metadata of a type at runtime?

Haskell語言學習筆記(81)Data.Typeable