如果单子y
和f
是单向的话,是否可以将x
解析为N
和M
的函数?
x :: M (N X)
f :: X -> M (N Y)
-- pattern matching not allowed, one-way monads implied
y :: M (N Y)
y = _
完整定义:
data X = X
data Y = Y
-- pattern matching not allowed, one-way monads implied
data M a = M a
data N a = N a
instance Functor M where
fmap = undefined
instance Applicative M where
pure = undefined
(<*>) = undefined
instance Monad M where
(>>=) = undefined
instance Functor N where
fmap = undefined
instance Applicative N where
pure = undefined
(<*>) = undefined
instance Monad N where
(>>=) = undefined
x :: M (N X)
x = undefined
f :: X -> M (N Y)
f = undefined
-- pattern matching not allowed, one-way monads implied
y :: M (N Y)
y = _
我的直觉是,这通常不可能,而且它与monad变形金刚解决的问题有关,但我不确定。