[Haskell-beginners] Question about example in 'using do notation with Writer' section of LYH

Olumide 50295 at web.de
Thu Jan 26 15:41:35 UTC 2017


Hello List,

Chapter 14 of LYH ( 
http://learnyouahaskell.com/for-a-few-monads-more#reader ) has the 
following bit of code:


import Control.Monad.Writer

logNumber :: Int -> Writer [String] Int
logNumber x = Writer (x, ["Got number: " ++ show x])

multWithLog :: Writer [String] Int
multWithLog = do
     a <- logNumber 3
     b <- logNumber 5
     return (a*b)

I have a fair grasp of what's going bu the last line return(a*b) eludes 
me. Specifically its the a*b part that baffles me. I think 3 is bound to 
'a' and 5 to 'b', then return(a*b) would put the value 15 in a context 
... So what becomes of the string parts of the Writer monads created by 
logNumber 3 and logNumber 5 respectively.

Regards,

- Olumide


More information about the Beginners mailing list