了解一下Haskell有一个关于仿函数的例子.我可以阅读LYAH和文本,并弄清楚应该发生什么 - 但我不知道写这样的东西.我经常在Haskell中发现这个问题.
instance Functor (Either a) where
fmap f (Right x) = Right (f x)
fmap f (Left x) = Left x
Run Code Online (Sandbox Code Playgroud)
但是,我很困惑..为什么不这个补充
instance Functor (Either a) where
fmap f (Right x) = Right (x)
fmap f (Left x) = Left (f x)
Run Code Online (Sandbox Code Playgroud)
如果f没有在顶部定义中使用,那么还有什么限制x使得它无法满足Left