Question: 7) [3 pts] Do all in Haskell Please! The following Haskell function, maxL, returns the maximum value in a given list of positive integers. maxL
7) [3 pts] Do all in Haskell Please!
The following Haskell function, maxL, returns the maximum value in a given list of positive integers.
maxL iL = foldl max 0 iL
We define a function maxLE (standing for maximum of a List, possibly Empty) that returns Nothing when given the empty list and returns Just v when given a non-empty list and v is the maximum value in that list.
For example, maxLE [2,5,1]) is Just 5.
maxLE can be implemented using foldl like this: maxLE iL = foldl maxMaybe Nothing iL
- [1 pt]
Give a definition of the maxMaybe function that will work with the above definition of maxLE.
- [1 pt]
Assume we reimplement maxLE using foldr like this: maxLE2 iL = foldr maxMaybe2 Nothing iL
Give a definition of the maxMaybe2 function that will work with foldr.
- [1 pt]
Will the above definition of maxLE work for lists that contain only negative integers? Explain your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
