Monadic“双重绑定”

时间:2017-08-15 18:15:08

标签: haskell monads

如果单子yf是单向的话,是否可以将x解析为NM的函数?

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变形金刚解决的问题有关,但我不确定。

0 个答案:

没有答案