Skip to content

Commit 832845b

Browse files
committed
Use Int for replicateM
1 parent 30467f1 commit 832845b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

bower.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"bower.json",
1717
"Gruntfile.js",
1818
"package.json"
19-
]
19+
],
20+
"dependencies": {
21+
"purescript-integers": "~0.1.0"
22+
}
2023
}

src/Control/Monad.purs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
module Control.Monad where
44

5+
import Data.Int (Int())
6+
57
-- | Perform a monadic action `n` times collecting all of the results.
6-
replicateM :: forall m a. (Monad m) => Number -> m a -> m [a]
7-
replicateM 0 _ = return []
8-
replicateM n m = do
9-
a <- m
10-
as <- replicateM (n - 1) m
11-
return (a : as)
8+
replicateM :: forall m a. (Monad m) => Int -> m a -> m [a]
9+
replicateM n m | n == zero = return []
10+
| otherwise = do a <- m
11+
as <- replicateM (n - one) m
12+
return (a : as)
1213

1314
-- | Perform a fold using a monadic step function.
1415
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
@@ -27,7 +28,7 @@ unless true _ = return unit
2728

2829
-- | Filter where the predicate returns a monadic `Boolean`.
2930
-- |
30-
-- | For example:
31+
-- | For example:
3132
-- |
3233
-- | ```purescript
3334
-- | powerSet :: forall a. [a] -> [[a]]

0 commit comments

Comments
 (0)