小编thy*_*222的帖子

为Typeable编写实例声明而不导出

如何为Typeable编写实际的实例声明?例如,假设我想为Char编写一个实例,其中每个角色都有不同的类型,例如

instance Typeable Char where
    typeOf 'a' = C
    typeOf 'b' = C -> D
    typeOf 'c' = D -> E
    typeOf     = String
Run Code Online (Sandbox Code Playgroud)

显然这不会像这样写,因为typeOf的输出是TypeRep,但我无法弄清楚如何实际构造TypeRep.

这甚至可能吗?似乎所有关于Typeable的内容都假定您将使用DeriveDataTypeable.

haskell types instance

10
推荐指数
1
解决办法
768
查看次数

标签 统计

haskell ×1

instance ×1

types ×1