
On Sun, Jan 27, 2013 at 09:29:27PM +0100, Emmanuel Touzery wrote:
stats :: String -> String stats = unwords . sequence [show . length . words, show . length . lines, show . length]
[..]
This improves the statistics code slightly, but uses some monadic machinery you may not be familiar with. Another way to read the 'stats' function is this:
stats :: String -> String stats str = unwords [show . length . words $ str, show . length . lines $ str, show . length $ str]
I'm sorry, may I ask on which monad here is "sequence" operating?
I can see that sequence here turns [a->a] into a->[a], I'm just not sure which is the monad at play here... I just need a little bit more explanation about this code before I get it.
It is the ((->) a) monad, also known as the reader monad. -Brent