Maximum value in a list

Dean Herington heringto@cs.unc.edu
Mon, 05 May 2003 10:23:38 -0400


sashan wrote:

> Hi
>
> I was reading through the tutorial Yet Another Haskell Tutorial and
> doing chapter 3 ex 5, write a function using foldr and max to return the
> maximum value in a list.
>
> I came up with the following that will work for positive numbers.
>
> maxInList :: [Int]->Int
> maxInList [] = 0
> maxInList l = foldr max 0 l
>
> Is there an identity for the max function? Because currently if the list
>   [-1,-3,-4] is passed to maxInList it will return 0.

Hint: Find a better value than `0` to give as the second argument to
`foldr`.

Dean