如何声明此数据类型的Functor实例:
data Productish a b = Productish a b
我已经尝试过:
instance (Functor a, Functor b) => Productish a b where
fmap f (Productish a b) = Productish (f a) (f b)
但是编译器显示错误:
error: ‘fmap’ is not a (visible) method of class ‘Productish’
首先,您的语法错误。要在Functor
上定义Productish
实例,您需要执行instance Functor (Productish a b) where …
。