3 ms·
sequence_ $ take 100 $ repeat $ putStrLn "Hello, World" alternatively, mapM_ putStrLn $ take 100 $ repeat "Hello, World"
by masklinn 15y ago
sequence_ $ take 100 $ repeat $ putStrLn "Hello, World"
alternatively,
mapM_ putStrLn $ take 100 $ repeat "Hello, World"
- jewbacca 15y ago[see above]
- masklinn 15y agoOh, didn't know about `replicateM_`. Not sure I like it much though, seems... redundant.
- jewbacca 15y agoIt's a pretty common pattern, I think it's worth its own word, at least as much as mapM: mapM f xs = sequence (map f xs) replicateM n x = sequence (replicate n x) Another cool thing replicateM is equivalent to: for lists, it's the cartesian power (sequence is the cartesian product). ...this is actually the primary reason I'm aware of it.
- deleted 15y ago[deleted]