Skip to content

How should I use Writer? #1688

Answered by THOUSAND-SKY
timongh asked this question in Q&A
Mar 29, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I would myself like an example of this:

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)  

(from http://learnyouahaskell.com/for-a-few-monads-more#writer ) Although I realize that example is outdated (see https://stackoverflow.com/questions/11684321/how-to-play-with-control-monad-writer-in-haskell )

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gcanti
Comment options

Answer selected by timongh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants