2 ms·
fold is a natural consequence of church lists, probably the most fundamental way of expressing the list abstraction: \f \x (f a0 (f a1 (f a2 x))) So fold is j
by somewhereoutth 3y ago
fold is a natural consequence of church lists, probably the most fundamental way of expressing the list abstraction:
\f \x (f a0 (f a1 (f a2 x)))
So fold is just applying a list (function) to 2 arguments. Or you can be helpful and make something like fold := \f \x \l l f x which is useful for binding the f and the x and applying to multiple lists (everything is Curried of course)
LISP is not quite based on lambda calculus, so it should be no surprise it doesn't quite get reduce(i.e. fold) right.
See also church numerals, which are like lists but without the elements, they also have a 'fold':
\f \x f (f (f x))) == 3
We can make trees! Which again also have a 'fold'
\f \x f a0 (x a1) (f a2 (x a3) (x a4))
And many other more exotic folding data structures.