On Feb 10, 2008 9:33 PM, Thomas Hartman <[EMAIL PROTECTED]> wrote:
> -- using writer monad
> -- Nothing unsafe here, pure referrentially transparent goodness
> myfoldrW f z [] = return z
> myfoldrW f z (x:xs) = do
> r <- (myfoldrW f z xs)
> tell ("x,r: " ++ (show (x,r)) ++ "\n" )
> return $ x `f` r
*Main> foldr const 0 [1..]
1
*Main> putStrLn $ snd $ runWriter $ myfoldrW const 0 [1..]
Interrupted.
One of the good things from foldr is the possibility of
"short-circuiting", so to speak. However I don't know if it is
possible to show this using the writer monad, as is would involve
observing if the function is strict or not in its second argument.
Cheers,
--
Felipe.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe