How should I use Writer? #1688
-
Are there any examples of how to use Writer? |
Beta Was this translation helpful? Give feedback.
Answered by
THOUSAND-SKY
Sep 25, 2022
Replies: 1 comment 1 reply
-
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 ) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
timongh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would myself like an example of this:
(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 )