I tried to solve a problem that required the maximum value of the list after the function was displayed. The list is a range from a to b, where a> b or b> a. Since Haskell can also define shrinking lists, I thought I didn't need to check if a> b was there, and there was no need to throw borders to b..a. The function looks something like this:
f a b = maximum . map aFunction $ [a..b]
But if the list is reduced, i.e. a> b, then Haskell gives me an exception:
Prelude.maximum: empty list
Thus, for some reason, a decreasing list passes an empty list to the maximum function. Why is this?
I know what maximumis defined in terms foldl1 maxand what foldl1needs a non- [10..1]empty list, but I do not know why such a list as is empty when passed foldl1.
source
share