<div>Thanks you Ivan and David for clarifying this.</div>
<div> </div>
<div>Best Regards,</div>
<div> </div>
<div>Chris<br><br></div>
<div class="gmail_quote">On Sat, Sep 18, 2010 at 3:55 AM, Ivan Lazar Miljenovic <span dir="ltr"><<a href="mailto:ivan.miljenovic@gmail.com">ivan.miljenovic@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div class="h5">On 18 September 2010 17:51, Christopher Tauss <<a href="mailto:ctauss1@gmail.com">ctauss1@gmail.com</a>> wrote:<br>> Hello Haskell Community -<br>><br>> I am a professional programmer with 11 years experience, yet I just do not<br>
> seem to be able to get the hang of even simple things in Haskell. I am<br>> trying to write a function that takes a list and returns the last n<br>> elements.<br>><br>> There may be a function which I can just call that does that, but I am<br>
> trying to roll my own just to understand the concept.<br>><br>> Let's call the function n_lastn and, given a list [1,2,3,4,5], I would like<br>> n_lastn 3 = [3,4,5]<br>><br>> Seems like it would be something like:<br>
><br>> n_lastn:: [a]->Int->[a]<br>> n_lastn 1 (xs) = last(xs)<br>> n_lastn n (x:xs) = ????<br>><br>> The issue is I do not see how you can store the last elements of the list.<br><br></div></div>Easiest way I can think of:<br>
<br>n_lastn n = reverse . take n . reverse<br><br>Alternatively:<br><br>n_lastn n xs = drop (len - n) xs<br> where<br> len = length xs<br><font color="#888888"><br>--<br>Ivan Lazar Miljenovic<br><a href="mailto:Ivan.Miljenovic@gmail.com">Ivan.Miljenovic@gmail.com</a><br>
<a href="http://ivanmiljenovic.wordpress.com/" target="_blank">IvanMiljenovic.wordpress.com</a><br></font></blockquote></div><br>