What is Haskell's Data.Typeable?

后端 未结 4 1272
孤街浪徒
孤街浪徒 2021-01-30 00:57

I\'ve come across references to Haskell\'s Data.Typeable, but it\'s not clear to me why I would want to use it in my code.

What problem does it solve, and h

4条回答
  •  一个人的身影
    2021-01-30 01:32

    It's a library that allows, among other things, naming types. If a type a is declared Typeable, then you can get its name using show $ typeOf x where x is any value of type a. It also features limited type-casting.

    (This is somewhat similar to C++'s RTTI or dynamic languages' reflection.)

提交回复
热议问题