<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Procedural Code in Functional Clothing?</title>
	<atom:link href="http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/feed/" rel="self" type="application/rss+xml" />
	<link>http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/</link>
	<description></description>
	<lastBuildDate>Wed, 25 Jan 2012 15:21:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/#comment-73</link>
		<dc:creator><![CDATA[Daniel Spiewak]]></dc:creator>
		<pubDate>Thu, 02 Oct 2008 05:40:23 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=167#comment-73</guid>
		<description><![CDATA[List&#039;s implementation is *purely* to squeeze every last drop of performance out of the data structure.  Even with Scala&#039;s limited tail recursion optimization, writing code in the functional style is still a *lot* less efficient at runtime than the imperative.  This is something which even the strongest FP advocates will admit to.  The primary reason to use FP over imperative is cleanliness and maintainability.  As you said, James&#039;s implementation of a linked list is quite sharp.  You can actually do a little better if you take a list to be defined purely as a cons cell (he was making a point about fold), but you get the picture.

The only performance benefits (that I know of) to writing code in the functional style come in the form of concurrency support.  Support for multi-threading literally comes for free in functional languages.  You don&#039;t need to worry about locking or anything messy like that since nothing is mutable.  Don&#039;t get me wrong, abstractions like actors really help, but they are merely an embodiment of the functional style: shared-nothing continuations passing.  Code written imperatively can still perform well asynchronously, but it is much harder to do.]]></description>
		<content:encoded><![CDATA[<p>List&#8217;s implementation is *purely* to squeeze every last drop of performance out of the data structure.  Even with Scala&#8217;s limited tail recursion optimization, writing code in the functional style is still a *lot* less efficient at runtime than the imperative.  This is something which even the strongest FP advocates will admit to.  The primary reason to use FP over imperative is cleanliness and maintainability.  As you said, James&#8217;s implementation of a linked list is quite sharp.  You can actually do a little better if you take a list to be defined purely as a cons cell (he was making a point about fold), but you get the picture.</p>
<p>The only performance benefits (that I know of) to writing code in the functional style come in the form of concurrency support.  Support for multi-threading literally comes for free in functional languages.  You don&#8217;t need to worry about locking or anything messy like that since nothing is mutable.  Don&#8217;t get me wrong, abstractions like actors really help, but they are merely an embodiment of the functional style: shared-nothing continuations passing.  Code written imperatively can still perform well asynchronously, but it is much harder to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/#comment-68</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Tue, 30 Sep 2008 12:58:45 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=167#comment-68</guid>
		<description><![CDATA[And by the way, I really enjoyed your popular &lt;a href=&quot;http://james-iry.blogspot.com/2007/09/monads-are-elephants-part-1.html&quot; rel=&quot;nofollow&quot;&gt;Monads are Elephants&lt;/a&gt; series.]]></description>
		<content:encoded><![CDATA[<p>And by the way, I really enjoyed your popular <a href="http://james-iry.blogspot.com/2007/09/monads-are-elephants-part-1.html" rel="nofollow">Monads are Elephants</a> series.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/#comment-67</link>
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Tue, 30 Sep 2008 12:52:36 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=167#comment-67</guid>
		<description><![CDATA[Wow, thanks for that code, James.  That is sharp looking, and it&#039;s more like what I expected to find in the first place.

Is that the reason scala.List looks the way it does, performance?  There&#039;s very little (or maybe nothing) that&#039;s more important than performance at this foundational level so I understand that one makes compromises, but it&#039;s not exactly a vote of confidence in the practicality of functional code.]]></description>
		<content:encoded><![CDATA[<p>Wow, thanks for that code, James.  That is sharp looking, and it&#8217;s more like what I expected to find in the first place.</p>
<p>Is that the reason scala.List looks the way it does, performance?  There&#8217;s very little (or maybe nothing) that&#8217;s more important than performance at this foundational level so I understand that one makes compromises, but it&#8217;s not exactly a vote of confidence in the practicality of functional code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://oldfashionedsoftware.com/2008/09/30/procedural-code-in-functional-clothing/#comment-66</link>
		<dc:creator><![CDATA[James Iry]]></dc:creator>
		<pubDate>Tue, 30 Sep 2008 07:43:34 +0000</pubDate>
		<guid isPermaLink="false">http://matthewmalone.wordpress.com/?p=167#comment-66</guid>
		<description><![CDATA[If performance is no object and you want cleanliness, folds are pretty universal

object MyList {
  // syntactically easy way to create a list
  def apply[A](elems : A *) = 
    elems.foldRight(MyNil:MyList[A]) {case (head, accum) =&gt; MyCons(head, accum)}
}

sealed abstract class MyList[+A] {
  def head : A
  def tail : MyList[A]
  
  def foldLeft[B](init:B)(f:(A,B) =&gt; B) : B = {
    def loop(lst:MyList[A], accum:B) : B = lst match {
      case MyCons(head, tail) =&gt; loop(tail, f(head, accum))
      case _ =&gt; accum
    }
  
    loop(this, init)
  }
  
  def reverse : MyList[A] =
    foldLeft(MyList[A]()){(head, accum) =&gt; MyCons(head, accum)}
  
  def foldRight[B](init:B)(f:(A,B) =&gt; B) : B =
    reverse.foldLeft(init)(f)
  
  def length : Int = 
    foldLeft(0) {case (_, accum) =&gt; accum + 1}
  
  def indices : MyList[Int] =
    foldRight((MyList[Int](), 0)) {case (_, (accum, count)) =&gt; (MyCons(count, accum), count +1 )} _1
    
  def last : A = 
    reverse.head
  
  def foreach(f:A =&gt; Unit) : Unit =
    foldLeft(()) {case (head, _) =&gt; f(head)}
  
  def map[B](f:A =&gt; B) : MyList[B] =
    foldRight(MyList[B]()) {case (head, accum) =&gt; MyCons(f(head), accum)}
  
}

case class MyCons[+A](head:A, tail:MyList[A]) extends MyList[A]

case object MyNil extends MyList[Nothing] {
  override def head = error (&quot;head of an empty list&quot;)
  override def tail = error (&quot;tail of an empty list&quot;)  
}]]></description>
		<content:encoded><![CDATA[<p>If performance is no object and you want cleanliness, folds are pretty universal</p>
<p>object MyList {<br />
  // syntactically easy way to create a list<br />
  def apply[A](elems : A *) =<br />
    elems.foldRight(MyNil:MyList[A]) {case (head, accum) =&gt; MyCons(head, accum)}<br />
}</p>
<p>sealed abstract class MyList[+A] {<br />
  def head : A<br />
  def tail : MyList[A]</p>
<p>  def foldLeft[B](init:B)(f:(A,B) =&gt; B) : B = {<br />
    def loop(lst:MyList[A], accum:B) : B = lst match {<br />
      case MyCons(head, tail) =&gt; loop(tail, f(head, accum))<br />
      case _ =&gt; accum<br />
    }</p>
<p>    loop(this, init)<br />
  }</p>
<p>  def reverse : MyList[A] =<br />
    foldLeft(MyList[A]()){(head, accum) =&gt; MyCons(head, accum)}</p>
<p>  def foldRight[B](init:B)(f:(A,B) =&gt; B) : B =<br />
    reverse.foldLeft(init)(f)</p>
<p>  def length : Int =<br />
    foldLeft(0) {case (_, accum) =&gt; accum + 1}</p>
<p>  def indices : MyList[Int] =<br />
    foldRight((MyList[Int](), 0)) {case (_, (accum, count)) =&gt; (MyCons(count, accum), count +1 )} _1</p>
<p>  def last : A =<br />
    reverse.head</p>
<p>  def foreach(f:A =&gt; Unit) : Unit =<br />
    foldLeft(()) {case (head, _) =&gt; f(head)}</p>
<p>  def map[B](f:A =&gt; B) : MyList[B] =<br />
    foldRight(MyList[B]()) {case (head, accum) =&gt; MyCons(f(head), accum)}</p>
<p>}</p>
<p>case class MyCons[+A](head:A, tail:MyList[A]) extends MyList[A]</p>
<p>case object MyNil extends MyList[Nothing] {<br />
  override def head = error (&#8220;head of an empty list&#8221;)<br />
  override def tail = error (&#8220;tail of an empty list&#8221;)<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

