Skip to content

Commit 9464e86

Browse files
Indicate that Array monad is a nested for loop
1 parent fcc3173 commit 9464e86

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Control/Monad.purs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ import Data.Unit (Unit)
3131
class (Applicative m, Bind m) <= Monad m
3232

3333
instance monadFn :: Monad ((->) r)
34+
35+
-- | The `Array` monad's "do notation" works like a nested for loop:
36+
-- | ```
37+
-- | foo :: Array Int
38+
-- | foo = do
39+
-- | eachElementInArray1 <- [0, 1]
40+
-- | eachElementInArray2 <- [1, 2]
41+
-- | pure (eachElementInArray1 + eachElementInArray2)
42+
-- |
43+
-- | foo == [(0 + 1), (0 + 2), (1 + 1), (1 + 2)] == [1, 2, 2, 3]
44+
-- | ```
3445
instance monadArray :: Monad Array
3546

3647
-- | `liftM1` provides a default implementation of `(<$>)` for any

0 commit comments

Comments
 (0)