
On Sun, Jun 5, 2011 at 2:24 PM, Elvio Toccalino
On Sun, 2011-06-05 at 19:46 +0100, Sean Charles wrote:
My confusion arises over: mapM_ putStrLn (traincodes legodata) Given that: mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
Here's how I read it: For any m that is a Monad, mapM_ takes a function that "takes an 'a' and returns it wrapped in a monad", a "list of a's" and returns a "monad containing 'unit'", the empty-list LISP-() undefined voidy thing.
There's another way to see it, which I found to be enlightening: mapM_ takes an "action" in the monad 'm', which needs an input of some type 'a' to run, and a list of appropriate input; it'll feed the input to the action repetitively, discarding the results. It's cousin mapM does the same, except it collects the results of running the action each time (preserving the original order in the input list).
I think that this is the more helpful way to look at it, personally. Also, in case you're not aware, it might might be helpful to know that the postfix underscore is part of a naming convention[1], so when you see that (particularly with respect to monads), you can expect (but are not guaranteed!) similar behavior. The postfix capital 'M' is also part of a convention, as noted in the link. [1] http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html#g:... Michael