Haskel-有两个争论的数据实例

问题描述 投票:2回答:1

如何声明此数据类型的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’
haskell
1个回答
6
投票

首先,您的语法错误。要在Functor上定义Productish实例,您需要执行instance Functor (Productish a b) where …

© www.soinside.com 2019 - 2024. All rights reserved.