我需要为特定数据类型声明一个 Monad 实例:
data M m a = Mk (m (Maybe a))
instance (Monad m) => Monad (M m) where
return x = Mk (m (Just x))
Mk (m (Nothing)) >>= f = Mk (m (Nothing))
Mk (m (Just x)) >>= f = f x
但我得到:
test.hs:6:7: Parse error in pattern: m
Failed, modules loaded: none.
这可能很简单,但我无法弄清楚!