Compute the maximum element from a list of numbers by foldin
Compute the maximum element from a list of numbers by folding. What is the initial value to choose for passing to FoldL or FoldR(remember: there is no smallest integer)? Which version of folding are you using (FoldL or FoldR)? Why?
Solution
Initial value to pass can be first number from the list
Both FoldL and FoldR can work, only difference would be that one will operate from left to right, and another from right to left.
For example, it can be like:
Given L = [a1 a2 .... an ]
MaxList( L ) can be defined as (FoldL max a1 L ) where max is function that return maximum of two numbers
