[Haskell-cafe] A systematic method for deriving a defintion of foldl using foldr?

Adrian Neumann aneumann at inf.fu-berlin.de
Wed Mar 11 14:33:47 EDT 2009


Read this excellent paper:

http://www.cs.nott.ac.uk/~gmh/fold.pdf


Am 11.03.2009 um 19:24 schrieb R J:

> foldl and foldr are defined as follows:
>
>   foldr                :: (a -> b -> b) -> b -> [a] -> b
>   foldr f e []         =  e
>   foldr f e (x : xs)   =  f x (foldr f e xs)
>
>   foldl                :: (b -> a -> b) -> b -> [a] -> b
>   foldl f e []         =  e
>   foldl f e (x : xs)   =  foldl f (f e x) xs
>
> 1.  I understand how these definitions work, and yet I'm unable to  
> implement foldl in terms of foldr.  What's a systematic approach to  
> identifying such an implementation, and what is the implementation?
>
> 2.  I believe that the reverse implementation--namely, implementing  
> foldr in terms of foldl--is impossible.  What's the proof of that?
>
> 3.  Any advice on how, aside from tons of practice, to develop the  
> intuition for rapidly seeing solutions to questions like these  
> would be much appreciated.  The difficulty a newbie faces in  
> answering seemingly simple questions like these is quite discouraging.
>
> Express your personality in color! Preview and select themes for  
> Hotmail®. See how.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: Signierter Teil der Nachricht
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090311/4d9514ad/PGP.bin


More information about the Haskell-Cafe mailing list