maxList

Nuno Silva nunopedrosilva@yahoo.com
Fri, 13 Sep 2002 07:42:45 -0700 (PDT)


--0-1537142547-1031928165=:31160
Content-Type: text/plain; charset=us-ascii


hello, I'm new to haskell, I'm studying for an exam, and I'm having trouble with this exercise.

I have a list of Integers, and I want to return the highest value of all.

i have this: 

comp :: Int -> Int -> Int

comp x y | x < y        = y

               | otherwise   = x

maxList :: [Int] -> [Int]

maxList (x1:x2:xs) = comp x1 x2 : maxList xs

maxList [] = []

 

this code returns a list, but I only want it to return a single Int... but can't seem to do it, could you please help me?



---------------------------------
Do you Yahoo!?
Yahoo! News - Today's headlines
--0-1537142547-1031928165=:31160
Content-Type: text/html; charset=us-ascii

<P>hello, I'm new to haskell, I'm studying for an exam, and I'm having trouble with this exercise.</P>
<P>I have a list of Integers, and I want to return the highest value of all.</P>
<P>i have this: </P>
<P>comp :: Int -&gt; Int -&gt; Int</P>
<P>comp x y | x &lt; y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = y</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise&nbsp;&nbsp;&nbsp;= x</P>
<P>maxList :: [Int] -&gt; [Int]</P>
<P>maxList (x1:x2:xs) = comp x1 x2 : maxList xs</P>
<P>maxList [] = []</P>
<P>&nbsp;</P>
<P>this code returns a list, but I only want it to return a single Int... but can't seem to do it, could you please help me?</P><p><br><hr size=1>Do you Yahoo!?<br>
<b><a href="http://news.yahoo.com/">Yahoo! News</a></b> - Today's headlines
--0-1537142547-1031928165=:31160--