Jump to content

Talk:Fold (higher-order function)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Cgibbard (talk | contribs) at 02:22, 21 October 2006 (Rewrite). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Rewrite

As partially noted below, the article was rather terrible, containing numerous severe errors. (buggy scheme code, foldl and foldr being confused with respect to lazy evaluation, associativity and commutativity being confused, etc.) I've rewritten it and extended it somewhat. It is mildly Haskell-centric as far as the examples go, but Haskell can very well be treated as functional pseudocode, and very little of the content is really particular to Haskell, but could be implemented in most any language supporting higher-order functions.

-- Cgibbard 02:22, 21 October 2006 (UTC)[reply]

foldl and foldr

I see, the paragraph about foldl and foldr has nicely the facts correct and conclusions all wrong, but I don't want to think about the correct examples right now.

Concatenation is not commutative, right, but it still doesn't matter whether foldl or foldr is used, because concatenation is still associative.

Foldr "starts" from the right, right, but that's still the correct fold for infinite lists because the lazy processing starts to produce co-data from the "end" (outer scope). You can try with

foldr (:) [] [1..]
foldr (&&) True ([True,False] ++ repeat True) 

--TuukkaH 01:40, 27 August 2006 (UTC)[reply]