[Haskell-beginners] How does this function append the log to the beginning of the list?
jugree at lavabit.com
jugree at lavabit.com
Mon Dec 24 12:47:34 CET 2012
Hello.
Could you explain this example(0)? Could you show its step by step
execution?
gcd' :: Int -> Int -> Writer (DiffList String) Int
gcd' a b
| b == 0 = do
tell (toDiffList ["Finished with " ++ show a])
return a
| otherwise = do
result <- gcd' b (a `mod` b)
tell (toDiffList [show a ++ " mod " ++ show b ++ " = " ++ show (a
`mod` b)])
return result
Why does the above append the log to the beginning of the list?
What value will result have in the following?
result <- gcd' 2 (3 `mod` 2)
(0) http://learnyouahaskell.com/for-a-few-monads-more#writer
More information about the Beginners
mailing list