<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Translation: Look at Data.Sequence sometime.<br>
<br>
On 9/18/10 11:15 AM, Maciej Piechotka wrote:
<blockquote cite="mid:1284833730.3079.9.camel@localhost.localdomain"
type="cite">
<pre wrap="">On Sat, 2010-09-18 at 03:51 -0400, Christopher Tauss wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hello Haskell Community -
I am a professional programmer with 11 years experience, yet I just do
not seem to be able to get the hang of even simple things in Haskell.
I am trying to write a function that takes a list and returns the last
n elements.
There may be a function which I can just call that does that, but I am
trying to roll my own just to understand the concept.
Let's call the function n_lastn and, given a list [1,2,3,4,5], I
would like
n_lastn 3 = [3,4,5]
Seems like it would be something like:
n_lastn:: [a]->Int->[a]
n_lastn 1 (xs) = last(xs)
n_lastn n (x:xs) = ????
The issue is I do not see how you can store the last elements of the
list.
Thanks in advance.
ctauss
</pre>
</blockquote>
<pre wrap="">
I'll add my $0.03 - unless you are doing it to learn about lists rethink
your approach. Taking k elements from end of n-element list will be O(n)
operation.
For example with appropriate structures (like finger trees) it would
look like O(k) operation.
Regards
</pre>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Haskell-Cafe mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a>
</pre>
</blockquote>
<br>
</body>
</html>