[Haskell-cafe] Folding function composition: L or R?
Henning Thielemann
iakd0 at clusterf.urz.uni-halle.de
Wed Jul 7 08:24:01 EDT 2004
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 :-)
More information about the Haskell-Cafe
mailing list