Skip to content

Commit 0bfaad0

Browse files
Port Array's "do notation" explanation from Monad to Bind instance
1 parent 0fb3e86 commit 0bfaad0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Control/Bind.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ infixr 1 bindFlipped as =<<
6363
instance bindFn :: Bind ((->) r) where
6464
bind m f x = f (m x) x
6565

66+
-- | The `Array` monad's "do notation" works like a nested for loop:
67+
-- | ```
68+
-- | foo :: Array Int
69+
-- | foo = do
70+
-- | eachElementInArray1 <- [0, 1]
71+
-- | eachElementInArray2 <- [1, 2]
72+
-- | pure (eachElementInArray1 + eachElementInArray2)
73+
-- |
74+
-- | foo == [(0 + 1), (0 + 2), (1 + 1), (1 + 2)] == [1, 2, 2, 3]
75+
-- | ```
6676
instance bindArray :: Bind Array where
6777
bind = arrayBind
6878

src/Control/Monad.purs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ class (Applicative m, Bind m) <= Monad m
3232

3333
instance monadFn :: Monad ((->) r)
3434

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-
-- | ```
4535
instance monadArray :: Monad Array
4636

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

0 commit comments

Comments
 (0)