To clarify the question: “sum of squares” is a special function, because it has the property that it can be expressed in terms of bend plus lambda functionality, i.e.
sumSq = fold ((result, next) => result + next * next) 0
What functions f have this property, where dom f = { A tuples } , ran f :: B ?
Obviously, due to the mechanics of folding, the statement that f is added is a statement about the existence of h :: A * B -> B such that for any n> 0, x1, ..., xn in A, f ((x1,...xn)) = h (xn, f ((x1,...,xn-1))) .
The statement about the existence of h says almost the same as your condition that
f((x1, x2, ..., xn)) = f((f((x1, x2, ..., xn-1)), xn)) (*)
therefore you were almost right; the difference is that you need A=B , which is a bit more restrictive than the general fold fold function. More problematic, however, folding in general also assumes the initial value a , which is set to a = f nil . The main reason your wording (*) is incorrect is because it assumes that h is what f does for paired lists, but this is only true when h(x, a) = a . That is, in your example of the sum of the squares, the initial value that you gave Accumulate is 0, which does nothing when you add it, but there are functions with a bend expression where the initial value does something, and in this case we have a folded function that does not satisfy (*).
For example, take this function with a bend expression lengthPlusOne :
lengthPlusOne = fold ((result, next) => result + 1) 1
f (1) = 2 , but f(f(), 1) = f(1, 1) = 3 .
Finally, we give an example of functions on lists that are not expressed in terms of a fold. Suppose we used the black box function and tested it on these inputs:
f (1) = 1 f (1, 1) = 1 (1) f (2, 1) = 1 f (1, 2, 1) = 2 (2)
Such a function on tuples (= finite lists) obviously exists (we can simply define it so that these outputs are higher and equal to zero in any other lists). However, it does not add up, because (1) means h(1,1)=1 , and from (2) it follows h(1,1)=2 .
I do not know if there is any other terminology than just saying "function expressed as a fold." Perhaps a handy list function (left and right) is context-sensitive to describe it?