ADT 是免费的单子:
data Free f r = Free (f (Free f r)) | Pure r
我希望它派生Show
出来,以便在使用它时可以将其打印出来。例如,如果我有以下内容:
data T next = A next | B next deriving (Show)
aa = Free $ A $ Free $ B $ Pure ()
就像现在一样,如果我添加deriving (Show)
到Free
ADT,我会收到以下错误:
No instance for (Show (f (Free f r)))
arising from the first field of ‘Free’ (type ‘f (Free f r)’)
Possible fix:
use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Show (Free f r))
我想show aa
生成一个可打印的字符串。这可能吗?