summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2021-01-17 17:15:25 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-22 15:04:42 -0500
commit4bb9a349b5d002463b9fc4e9a3b6dbf77ea7c085 (patch)
tree6f6ccec2744bfe9edc8d150db2043589b9e78d5b
parentfcbf21aae2ce37854552b9313ca4c908c039a2d1 (diff)
downloadhaskell-4bb9a349b5d002463b9fc4e9a3b6dbf77ea7c085.tar.gz
Change replicateM doctest example
-rw-r--r--libraries/base/Control/Monad.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/libraries/base/Control/Monad.hs b/libraries/base/Control/Monad.hs
index dff11edf7e..86c15daf00 100644
--- a/libraries/base/Control/Monad.hs
+++ b/libraries/base/Control/Monad.hs
@@ -284,10 +284,11 @@ Core: https://gitlab.haskell.org/ghc/ghc/issues/11795#note_118976
-- and then returns the list of results:
--
-- ==== __Examples__
--- >>> replicateM 3 (putStrLn "a")
--- a
--- a
--- a
+--
+-- >>> import Control.Monad.State
+-- >>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1
+-- ([1,2,3],4)
+--
replicateM :: (Applicative m) => Int -> m a -> m [a]
{-# INLINABLE replicateM #-}
{-# SPECIALISE replicateM :: Int -> IO a -> IO [a] #-}
@@ -300,6 +301,14 @@ replicateM cnt0 f =
| otherwise = liftA2 (:) f (loop (cnt - 1))
-- | Like 'replicateM', but discards the result.
+--
+-- ==== __Examples__
+--
+-- >>> replicateM_ 3 (putStrLn "a")
+-- a
+-- a
+-- a
+--
replicateM_ :: (Applicative m) => Int -> m a -> m ()
{-# INLINABLE replicateM_ #-}
{-# SPECIALISE replicateM_ :: Int -> IO a -> IO () #-}