[英]Multi-argument monadic bind
Is there a >>=
for functions of two arguments? 对于两个参数的函数是否有>>=
Something like 就像是
bind2 :: m a -> m b -> (a -> b -> m c) -> m c
I don't know what clever combinators you could use to build this out of the standard library, but at the risk of stating the obvious it is pretty easy to implement yourself: 我不知道你可以使用哪些聪明的组合器来构建标准库,但是冒着明显的风险,很容易实现自己:
bind2 :: Monad m => (a -> b -> m c) -> m a -> m b -> m c
bind2 f ma mb = do
a <- ma
b <- mb
f a b
> bind2 (\a b -> [a,b]) [1,2,3] [4,5,6]
[1,4,1,5,1,6,2,4,2,5,2,6,3,4,3,5,3,6]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.