File tree 2 files changed +6
-4
lines changed
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
115
115
116
116
-- | Perform a monadic action `n` times collecting all of the results.
117
117
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
122
120
123
121
-- | Attempt a computation multiple times, requiring at least one success.
124
122
-- |
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ testArray = do
31
31
assert $ replicateM 0 (Just 1 ) == Just []
32
32
assert $ replicateM (-1 ) (Just 1 ) == Just []
33
33
34
+ log " replicateM should be stack safe"
35
+ let n = 50000
36
+ assert $ replicateM n (Just unit) == Just (replicate n unit)
37
+
34
38
-- some
35
39
-- many
36
40
You can’t perform that action at this time.
0 commit comments