这个问题来自http://blog.sigfpe.com/2007/04/trivial-monad.html上的文章“Trivial Monad” 。提供的答案是
h x y = x >>= (\x -> g x y)
或等效地(在文章的上下文中)
h :: W Int -> W Int -> W Int
h x y = bind ( \x-> g x y ) x
其中 g 是
g :: Int -> W Int -> W Int
g x y = y >>= (return . (+x))
对于单子:
data W a = W a deriving Show
现在我有点困惑,如果 xInt
作为第一个参数但 x 是,你怎么能把 x 放在 g 中W Int
?