I came along this piece of coding on this website:
Input: foldr (/) 2 [8,12,24,4]
Output: 8.0
How is this Output being calculated ?
is it 8/(12/(24/(4/2))) = 8.0 ?
I came along this piece of coding on this website:
Input: foldr (/) 2 [8,12,24,4]
Output: 8.0
How is this Output being calculated ?
is it 8/(12/(24/(4/2))) = 8.0 ?
Yes.
Oh, Stack Overflow doesn't allow short answers. Ok then, a short explanation is in order (although I think you understand it already).
foldris defined as:In simple and more descriptive terms:
where
function_to_applyis applied on each element of the list from right to left something like this:Or in case of an infix function (such as the
/operator):Note that
(/)in your expression is just short for:Therefore, your example is calculated like this:
Which is exactly what you described.