Comment

Comment by jfarmer

Here's a neat paper on fold by Graham Hutton: "A tutorial on the universality and expressiveness of fold"

https://www.cs.nott.ac.uk/~pszgmh/fold.pdf

It gives a sufficient and necessary condition for when a function can be written as a (right) fold.

It's not clear whether the author means to say foldl and foldr are equivalent, or only that any foldl call which terminates can be converted into a foldr call.

The latter is true, but the former is false.

For finite lists, every foldl call can be translated into a foldr call that produces the same result (and vice versa).

Foldr still makes sense for infinite lists in a language w/ lazy evaluation, but foldl will recurse forever.

parent jfarmer 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton