4 ms·
An alternative way of viewing this is: find the recursive definition of that function, and think of its base case. For sum, it is something like sum([Head:Tail]
by cesarb 7y ago
An alternative way of viewing this is: find the recursive definition of that function, and think of its base case. For sum, it is something like sum([Head:Tail]) = Head + sum(Tail), which works only if sum([]) is 0. For prod, we have prod([Head:Tail]) = Head * prod(Tail), which again works only if prod([]) is 1. And for all, we have all([Head:Tail]) = Head && all(Tail), which again works only if all([]) is True.