Haskellsequence
函数的scala模拟是什么?
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:sequence
sequence
在 Haskell 中定义如下:
sequence :: Monad m => [m a] -> m [a]
sequence ms = foldr k (return []) ms
where
k m m' = do { x <- m; xs <- m'; return (x:xs) }
这里有一些用途:
ghci> sequence [Just 1, Just 2, Nothing, Just 3]
Nothing
ghci> sequence [[1,2],[3,4],[5,6]]
[[1,3,5],[1,3,6],[1,4,5],[1,4,6],[2,3,5],[2,3,6],[2,4,5],[2,4,6]]
提前致谢!