What is Haskell's Data.Typeable?

后端 未结 4 1189
孤街浪徒
孤街浪徒 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:25

    The Data.Typeable class is used primarily for generic programming in the Scrap Your Boilerplate (SYB) style. See also Data.Data

    The idea is that SYB defines a collection combinators for performing operations such as printing, counting, searching, substiting, etc in a uniform manner over a variety of user-created types. The Typeable typeclass provides the necessary plumbing.

    In modern GHC, you can just say deriving Data.Typeable when defining your own type in order to provide it with the necessary instances.

提交回复
热议问题