On 2/25/07, <b class="gmail_sendername">iliali16</b> &lt;<a href="mailto:iliali16@gmail.com">iliali16@gmail.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>Hi I am trying to implement the function drop in haskell the thing is that I<br>I have been trying for some time and I came up with this code where I am<br>trying to do recursion:<br><br>drop :: Integer -&gt; [Integer] -&gt; [Integer]
<br>drop 0 (x:xs) = (x:xs)<br>drop n (x:xs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|n &lt; lList (x:xs) = dropN (n-1) xs :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|otherwise = []</blockquote><div><br>drop :: Integer -&gt; [a] -&gt; [a]<br>drop n xs | n &lt; 1 =&nbsp; xs<br>drop _ [] =&nbsp; []
<br>drop n (_:xs) =&nbsp; drop (n-1) xs<br><br>Line 1: It specifies that drop will accept an Integer and a list, and return a list;<br>Line 2: If n &lt; 1, the function will return the list as it is (this pattern is matched if you&#39;re dropping 0 or -2 elements, for example);
<br>Line 3: No matter what Integer has been passed to the function, if the list passed is empty, an empty list will be returned as well;<br>Line 4: Dropping n elements from a list is equivalent to dropping n-1 elements from the tail (xs) of that same list.
<br><br>HTH<br>Antonio<br>-- <br></div></div><a href="http://antoniocangiano.com">http://antoniocangiano.com</a><br>Zen and the Art of Ruby Programming