Folding function composition: L or R?

I have a sequence of functions that I wish to fold together using function composition (.). Does it matter if I use foldl or foldr? e.g. [[ sss :: [ShowS] sss = map (++) ["abc","def","ghi","jkl"] ssr = foldr (.) id sss ssl = foldl (.) id sss sr = ssr "" sl = ssl "" -- sl == sr == "abcdefghijkl" -- is there any efficiency difference? ]] Conventional wisdom suggests that foldr is better, but I'm not sure if it really matters in this case. #g ------------ Graham Klyne For email: http://www.ninebynine.org/#Contact

On Wed, 7 Jul 2004, Graham Klyne wrote:
[[ sss :: [ShowS] sss = map (++) ["abc","def","ghi","jkl"]
ssr = foldr (.) id sss ssl = foldl (.) id sss
sr = ssr "" sl = ssl ""
-- sl == sr == "abcdefghijkl" -- is there any efficiency difference? ]]
Conventional wisdom suggests that foldr is better, but I'm not sure if it really matters in this case.
foldl performs worse, e.g. for infinite lists it will need infinite time :-)
participants (2)
-
Graham Klyne
-
Henning Thielemann