data A = Num Int
| Fun (A -> A) String deriving Show
instance Show (Fun (A -> A) String) where
show (Fun f s) = s
我想要一个函数的属性A -> A
来打印它,因此有一个String
类型参数Fun
。当我将它加载到 ghci 中时,我得到
/home/kmels/tmp/show-abs.hs:4:16:
Not in scope: type constructor or class `Fun'
我想这可以通过添加新的数据类型来实现
data FunWithAttribute = FA (A -> A) String
添加data A = Num Int | Fun FunWithAttribute
和编写instance Show FunWithAttribute
. 额外的数据类型是可以避免的吗?