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

Olumide 50295 at web.de
Thu Jan 26 18:00:08 UTC 2017


On 26/01/2017 16:02, David McBride wrote:
> Nothing happens to them.  They are still in there.  Whereas logNumber
> always returns the number you give it, multiWithLog always returns 15
> and appends two strings into its state ("got number 3 and 5").
>
> You can return whatever value you want from a Monad.  In this case
> he's doing a * b, but you could do 2 * b, Just (a + b) or anything
> else.  As an example, here I return a tuple instead.
>
> multWithLogTuple :: Writer [String] (Int,Int,Int)
> multWithLogTuple = do
>     a <- logNumber 3
>     b <- logNumber 5
>     return (a,b,2*b)
>

So return (a*b) still creates Writer [String] Int?

I thought the [String] parts of 'a' and 'b' ought to be in the result 
but I see it needn't.

- Olumide




More information about the Beginners mailing list