<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Infinite Lists for the Finitely Patient</title>
	<atom:link href="http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:01:44 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Gates</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4791</link>
		<dc:creator>David Gates</dc:creator>
		<pubDate>Sat, 21 Mar 2009 11:44:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4791</guid>
		<description>Good news: they&#039;re adding a cons operator to streams.  It&#039;s #:: to distinguish it from the list cons operator.

http://lampsvn.epfl.ch/trac/scala/ticket/1790</description>
		<content:encoded><![CDATA[<p>Good news: they&#8217;re adding a cons operator to streams.  It&#8217;s #:: to distinguish it from the list cons operator.</p>
<p><a href="http://lampsvn.epfl.ch/trac/scala/ticket/1790" rel="nofollow">http://lampsvn.epfl.ch/trac/scala/ticket/1790</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4346</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Tue, 25 Nov 2008 18:29:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4346</guid>
		<description>You would have to convert the List into a Stream:

def toStream[A](ls: List[A]): Stream[A] = ls match {
  case hd :: tail =&gt; hd :: toStream(tail)
  case Nil =&gt; Stream.empty
}

Then you could use the zip() method on either Stream.

Another (possibly better) approach for zipWithIndex would be to make use of Range:

def zipWithIndex[A](ls: List[A]) = (0 until ls.length).toList zip ls

It&#039;s a little less efficient, but you do get a List as a result, rather than a Stream.</description>
		<content:encoded><![CDATA[<p>You would have to convert the List into a Stream:</p>
<p>def toStream[A](ls: List[A]): Stream[A] = ls match {<br />
  case hd :: tail => hd :: toStream(tail)<br />
  case Nil => Stream.empty<br />
}</p>
<p>Then you could use the zip() method on either Stream.</p>
<p>Another (possibly better) approach for zipWithIndex would be to make use of Range:</p>
<p>def zipWithIndex[A](ls: List[A]) = (0 until ls.length).toList zip ls</p>
<p>It&#8217;s a little less efficient, but you do get a List as a result, rather than a Stream.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quintesse</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4345</link>
		<dc:creator>Quintesse</dc:creator>
		<pubDate>Tue, 25 Nov 2008 18:12:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4345</guid>
		<description>Well actually I think it&#039;s pretty cool it&#039;s possible at all.

But I had been thinking something more simple, I wanted to combine a List with a Stream, for example to associate the items in the List with their index (I know there is a zipWithIndex but let&#039;s forget about that one for now).</description>
		<content:encoded><![CDATA[<p>Well actually I think it&#8217;s pretty cool it&#8217;s possible at all.</p>
<p>But I had been thinking something more simple, I wanted to combine a List with a Stream, for example to associate the items in the List with their index (I know there is a zipWithIndex but let&#8217;s forget about that one for now).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4344</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Tue, 25 Nov 2008 17:39:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4344</guid>
		<description>The zip method does indeed work with infinite lists.  This brings about one of the oddest definitions of Fibonacci on record:

val fibs = 0 :: 1 :: fibs.zip(fibs.tail).map { case (a, b) =&gt; a + b }

It&#039;s all lazily evaluated, so once again, no infinite recursion.  I&#039;ll be the first to admit though that this is insanely weird.</description>
		<content:encoded><![CDATA[<p>The zip method does indeed work with infinite lists.  This brings about one of the oddest definitions of Fibonacci on record:</p>
<p>val fibs = 0 :: 1 :: fibs.zip(fibs.tail).map { case (a, b) => a + b }</p>
<p>It&#8217;s all lazily evaluated, so once again, no infinite recursion.  I&#8217;ll be the first to admit though that this is insanely weird.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quintesse</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4343</link>
		<dc:creator>Quintesse</dc:creator>
		<pubDate>Tue, 25 Nov 2008 17:35:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4343</guid>
		<description>Great stuff, but I was wondering if there was a way to use this together with the zip() method defined for Arrays and Lists? Although maybe the question should be put to the Scala designers that decided to make zip only take argumetns that are of the exact same type as the object ;)</description>
		<content:encoded><![CDATA[<p>Great stuff, but I was wondering if there was a way to use this together with the zip() method defined for Arrays and Lists? Although maybe the question should be put to the Scala designers that decided to make zip only take argumetns that are of the exact same type as the object <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4332</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 21 Nov 2008 16:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4332</guid>
		<description>@Michael

A connection is indeed opened and closed for each invocation of ancestors().  This may seem wasteful, but any connection pool is going to optimize that away.  It&#039;s fairly standard practice with JDBC (at least, with the projects I have worked on) to have very short-lived Connection objects.  This keeps your database model robust, since you don&#039;t need to worry about carrying around resources and disposing of them after the fact.

As implied above, the finally clause is executed with the ancestors() method returns.  This seems to happen after a recursion, but it doesn&#039;t thanks to the laziness of infinite lists.  The recursive invocation of ancestors() doesn&#039;t happen until we actually request the nth element of the list.  This also answers your second connection question, which was &quot;why don&#039;t we just close it once the list is done?&quot;  The answer is that we don&#039;t know that the list will *ever* be &quot;done&quot;, it is theoretically unbounded.  The best we could do is let whoever called ancestor() be responsible for closing the connection, but that would be moving a fair bit of semantic-dependent logic out of ancestors() and into the call-site.</description>
		<content:encoded><![CDATA[<p>@Michael</p>
<p>A connection is indeed opened and closed for each invocation of ancestors().  This may seem wasteful, but any connection pool is going to optimize that away.  It&#8217;s fairly standard practice with JDBC (at least, with the projects I have worked on) to have very short-lived Connection objects.  This keeps your database model robust, since you don&#8217;t need to worry about carrying around resources and disposing of them after the fact.</p>
<p>As implied above, the finally clause is executed with the ancestors() method returns.  This seems to happen after a recursion, but it doesn&#8217;t thanks to the laziness of infinite lists.  The recursive invocation of ancestors() doesn&#8217;t happen until we actually request the nth element of the list.  This also answers your second connection question, which was &#8220;why don&#8217;t we just close it once the list is done?&#8221;  The answer is that we don&#8217;t know that the list will *ever* be &#8220;done&#8221;, it is theoretically unbounded.  The best we could do is let whoever called ancestor() be responsible for closing the connection, but that would be moving a fair bit of semantic-dependent logic out of ancestors() and into the call-site.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chermside</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4331</link>
		<dc:creator>Michael Chermside</dc:creator>
		<pubDate>Fri, 21 Nov 2008 14:35:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4331</guid>
		<description>I&#039;m still wondering about mbana&#039;s question: when is the connection closed?

Sure, I see the finally clause, but I don&#039;t understand when it gets executed. Is a new connection opened (and closed) for each invocation of ancestors()? That sounds wasteful -- more useful might be to close it when the infinite list is &quot;done&quot;. (Would that be when it has been traversed to the end, when it gets garbage collected, or perhaps something else?)

This is, of course, a distraction from your main point. But I need to mull some time on your comment about infinite lists being &quot;packaged&quot; recursion before I come to enlighenment on that topic.</description>
		<content:encoded><![CDATA[<p>I&#8217;m still wondering about mbana&#8217;s question: when is the connection closed?</p>
<p>Sure, I see the finally clause, but I don&#8217;t understand when it gets executed. Is a new connection opened (and closed) for each invocation of ancestors()? That sounds wasteful &#8212; more useful might be to close it when the infinite list is &#8220;done&#8221;. (Would that be when it has been traversed to the end, when it gets garbage collected, or perhaps something else?)</p>
<p>This is, of course, a distraction from your main point. But I need to mull some time on your comment about infinite lists being &#8220;packaged&#8221; recursion before I come to enlighenment on that topic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4328</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Wed, 19 Nov 2008 10:56:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4328</guid>
		<description>&quot;Iterators aren’t first-class collections, which means that you can pass them to methods requiring a List (or the more flexible “Seq” in Scala), you can’t perform normal collection operations, etc. You also can’t subscript to a particular location (e.g. nats(4)).&quot;

See Google Collections - which is really Iterator centric - , there should be answers to all of those.

e.g.  get(Iterator iterator, int position) 

But I agree, Java developers should much more use Iterators than Lists, I guess 90% of the time they should use an iterator (&quot;infinite list&quot;) than a collection. That&#039;s sad with Java.

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>&#8220;Iterators aren’t first-class collections, which means that you can pass them to methods requiring a List (or the more flexible “Seq” in Scala), you can’t perform normal collection operations, etc. You also can’t subscript to a particular location (e.g. nats(4)).&#8221;</p>
<p>See Google Collections &#8211; which is really Iterator centric &#8211; , there should be answers to all of those.</p>
<p>e.g.  get(Iterator iterator, int position) </p>
<p>But I agree, Java developers should much more use Iterators than Lists, I guess 90% of the time they should use an iterator (&#8220;infinite list&#8221;) than a collection. That&#8217;s sad with Java.</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4327</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Tue, 18 Nov 2008 16:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4327</guid>
		<description>@mbana

Right here:

&lt;pre&gt;    } else Stream.empty
  } finally {
    conn.close()
  }&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@mbana</p>
<p>Right here:</p>
<pre>    } else Stream.empty
  } finally {
    conn.close()
  }</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: mbana</title>
		<link>http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient/comment-page-1#comment-4326</link>
		<dc:creator>mbana</dc:creator>
		<pubDate>Tue, 18 Nov 2008 15:30:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/infinite-lists-for-the-finitely-patient#comment-4326</guid>
		<description>In your last example; when are the &#039;Connections&#039;s closed? That is, if you&#039;ve got a lot of records you&#039;ll have a lot of connections open right?</description>
		<content:encoded><![CDATA[<p>In your last example; when are the &#8216;Connections&#8217;s closed? That is, if you&#8217;ve got a lot of records you&#8217;ll have a lot of connections open right?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
