Maximum value in a list

sashan sashang@ihug.co.nz
Mon, 05 May 2003 14:30:18 +1200


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.