4 ms·
100.times {puts "Hello, world"} I'm just sayin'.
by quarterto 14y ago
100.times {puts "Hello, world"}
I'm just sayin'.
- jewbacca 14y agoI'm not sure this will reflect well on Haskell that this is the most natural way I can think to write it. But I can pretty much guarantee replicateM_[0] is the most generalizable idiom in this whole comments section. replicateM_ 100 $ print "Hello World!" It's pretty to me, damnit. ----- [0] http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:replicateM http://hackage.haskell.org/packages/archive/base/latest/doc/...
- masklinn 14y agosequence_ $ take 100 $ repeat $ putStrLn "Hello, World" alternatively, mapM_ putStrLn $ take 100 $ repeat "Hello, World"
- jewbacca 14y ago[see above]
- masklinn 14y agoOh, didn't know about `replicateM_`. Not sure I like it much though, seems... redundant.
- jewbacca 14y 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 14y ago[deleted]