1
写这样的实例声明工作正常:与类型变量
data Either a b = Left a | Right b
instance Functor (Either a) where
fmap _ (Left x) = Left x
fmap f (Right x) = Right (f x)
现在可以说,我想这个反转,左应用于F到值:
instance Functor (Either a) where
fmap _ (Right x) = Right x
fmap f (Left x) = Left (f x)
这并不编译,我想我需要像Functor (Either _ b)
这样的东西,我该怎么做?
你不能,至少没有直接。你可以为'Either'做一个'newtype'包装器。 – melpomene