
ndmitchell:
Hi
However, it was pointed out that repeatM is next to useless, and it is traditional to use 'forever' for repeatM_ (see for example "Tackling the Awkward Squad", and http://haskell.org/haskellwiki/Roll_your_own_IRC_bot
That being said, repeatM_ isn't too bad, should people prefer it.
If I had to guess what the monadic version of repeat was, I'd guess repeatM_ before forever. Forever is a very overloaded word, repeat in Haskell has exactly one concrete meaning agreed by everyone (since its in the Prelude).
Agreed. But 'forever' is a pretty special control structures, worthy of a special name. Consider the cuteness of: listen = forever $ do h <- get s <- io (hGetLine h) io (putStrLn s) if ping s then pong s else eval (clean s) versus: listen = repeatM_ $ do h <- get s <- io (hGetLine h) io (putStrLn s) if ping s then pong s else eval (clean s) Or, to quote the awkward squad, s2.4 "Control structures":
We can easily express an infinite loop as a combinator:
forever :: IO () -> IO () forever a = a >> forever a
I'm we're going to use this forever more, then a name more meaningful than repeatM_ might be appropriate (personally, I have to check every time whether it is replicate or repeat that is :: Int -> a -> [a]). -- Don