Skip to content

Commit a235b86

Browse files
committed
Make replicateM stack safe
1 parent 709b255 commit a235b86

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Data/Array.purs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ foreign import replicate :: forall a. Int -> a -> Array a
115115

116116
-- | Perform a monadic action `n` times collecting all of the results.
117117
replicateM :: forall m a. (Monad m) => Int -> m a -> m (Array a)
118-
replicateM n m | n < 1 = return []
119-
| otherwise = do a <- m
120-
as <- replicateM (n - 1) m
121-
return (a : as)
118+
replicateM n m | n < 1 = return []
119+
| otherwise = sequence $ replicate n m
122120

123121
-- | Attempt a computation multiple times, requiring at least one success.
124122
-- |

0 commit comments

Comments
 (0)