File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff 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.
117117replicateM :: 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-- |
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ testArray = do
3131 assert $ replicateM 0 (Just 1 ) == Just []
3232 assert $ replicateM (-1 ) (Just 1 ) == Just []
3333
34+ log " replicateM should be stack safe"
35+ let n = 50000
36+ assert $ replicateM n (Just unit) == Just (replicate n unit)
37+
3438 -- some
3539 -- many
3640
You can’t perform that action at this time.
0 commit comments