Check whether a type is an instance of Show in Haskell?

前端 未结 3 1745
执笔经年
执笔经年 2020-11-30 10:48

Suppose I have a simple data type in Haskell for storing a value:

data V a = V a

I want to make V an instance of Show, regardless of a\'s t

3条回答
  •  感情败类
    2020-11-30 11:13

    Even if you could do this, it would be a bad design. I would recommend adding a Show constraint to a:

    instance Show a => Show (V a) where ...
    

    If you want to store members in a container data type that are not an instance of Show, then you should create a new data type fore them.

提交回复
热议问题