Maximum value in a list
Liyang HU
liyang@nerv.cx
Mon, 5 May 2003 03:51:19 +0100
On Mon, May 05, 2003 at 02:30:18PM +1200, sashan wrote:
> I came up with the following that will work for positive numbers.
> maxInList :: [Int]->Int
> maxInList [] = 0
> maxInList l = foldr max 0 l
Given that you've already taken care of the empty case, (and assuming you
think the maximum of an empty list is indeed zero) can't you just use foldr1
instead of foldr? (foldr1 f l is equivalent to foldr f (head l) (tail l))
Have fun in your adventures with Haskell, :)
/Liyang
--
.--| Liyang Hu |--| http://nerv.cx/ |--| Caius@Cam |--| ICQ: 39391385 |--.
| ::::::::::::: Ack. I don't even have a signature anymore. :::::::::::: |