<?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"
	>
<channel>
	<title>Comments on: Haskell &gt; Scala &gt; (Java 7  Functional Java) &gt; Java</title>
	<atom:link href="http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Tue, 07 Feb 2012 18:27:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Matt Lavin</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-68471</link>
		<dc:creator>Matt Lavin</dc:creator>
		<pubDate>Sun, 20 Feb 2011 01:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-68471</guid>
		<description>Tony, I'm intrigued by your comment about variable names.  I'm a fan of both Haskell and readable programs.  Can you explain what you mean when you say "It is extremely error-prone"?  How can a program with understandable variable names be harder to read than one without?  Additionally, I'd love to hear more about the "more disciplined approaches, which Haskell strives for and exhibits".  

I don't see why a Haskell program can't be written with comments and with good naming to be somewhat understandable to a person without a great deal of studying.  The example from Krzysztof or scm are both concise while staying easy to understand.</description>
		<content:encoded><![CDATA[<p>Tony, I&#8217;m intrigued by your comment about variable names.  I&#8217;m a fan of both Haskell and readable programs.  Can you explain what you mean when you say &#8220;It is extremely error-prone&#8221;?  How can a program with understandable variable names be harder to read than one without?  Additionally, I&#8217;d love to hear more about the &#8220;more disciplined approaches, which Haskell strives for and exhibits&#8221;.  </p>
<p>I don&#8217;t see why a Haskell program can&#8217;t be written with comments and with good naming to be somewhat understandable to a person without a great deal of studying.  The example from Krzysztof or scm are both concise while staying easy to understand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-43105</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Sat, 17 Jul 2010 04:13:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-43105</guid>
		<description>Alexander, your conclusions rest on incredibly brave assumptions. Specifically, that variable names are in some way useful for purporting meaning in a program. This is an incredibly sloppy way to read code. It is extremely error-prone (to a degree that is often under-estimated), clumsy and inefficient compared to more disciplined approaches, which Haskell strives for and exhibits.</description>
		<content:encoded><![CDATA[<p>Alexander, your conclusions rest on incredibly brave assumptions. Specifically, that variable names are in some way useful for purporting meaning in a program. This is an incredibly sloppy way to read code. It is extremely error-prone (to a degree that is often under-estimated), clumsy and inefficient compared to more disciplined approaches, which Haskell strives for and exhibits.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-43087</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Fri, 16 Jul 2010 07:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-43087</guid>
		<description>I find it interesting that only the C programs are properly commented.  One Java-program has a few comments, while the Haskell and other versions have no comments.

I'd like to understand whether this is because wordpress ate the comments from those haskell programs, or whether terseness is valued so highly by haskell programmers that comments go out the door.  The same applies to variable naming.  

The longest non-global variable name in the haskell programs is *two* characters long.  It's like C-programs from the 70s.  With that kind of naming convention, documentation is *needed* to understand the idea behind a function.  This again means that the code itself is unreadable.</description>
		<content:encoded><![CDATA[<p>I find it interesting that only the C programs are properly commented.  One Java-program has a few comments, while the Haskell and other versions have no comments.</p>
<p>I&#8217;d like to understand whether this is because wordpress ate the comments from those haskell programs, or whether terseness is valued so highly by haskell programmers that comments go out the door.  The same applies to variable naming.  </p>
<p>The longest non-global variable name in the haskell programs is *two* characters long.  It&#8217;s like C-programs from the 70s.  With that kind of naming convention, documentation is *needed* to understand the idea behind a function.  This again means that the code itself is unreadable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarg</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-42633</link>
		<dc:creator>Jarg</dc:creator>
		<pubDate>Sun, 04 Jul 2010 02:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-42633</guid>
		<description>This is a bit more idiomatic Haskell:
&lt;pre&gt;
matchBy matchFunc = null . foldl matchAll [] where
&#160;   matchAll []     c = [c]
&#160;   matchAll (s:ss) c &#124; matchFunc s c = ss
&#160;                     &#124; otherwise     = (c:s:ss)
matchBrackets = matchBy $ \x y -&#62; (x,y) `elem` [('[',']'),('{','}'),('(',')')]
&lt;/pre&gt;
A parsing lib seems a bit heavyweight for this simple example IMO.</description>
		<content:encoded><![CDATA[<p>This is a bit more idiomatic Haskell:</p>
<pre>
matchBy matchFunc = null . foldl matchAll [] where
&nbsp;   matchAll []     c = [c]
&nbsp;   matchAll (s:ss) c | matchFunc s c = ss
&nbsp;                     | otherwise     = (c:s:ss)
matchBrackets = matchBy $ \x y -&gt; (x,y) `elem` [('[',']'),('{','}'),('(',')')]
</pre>
<p>A parsing lib seems a bit heavyweight for this simple example IMO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scm</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-41464</link>
		<dc:creator>scm</dc:creator>
		<pubDate>Mon, 07 Jun 2010 15:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-41464</guid>
		<description>import System(getArgs)
consume s ('[':xs) = consume ('[':s) xs
consume ('[':s) (']':xs) = consume s xs
consume s ('(':xs) = consume ('(':s) xs
consume ('(':s) (')':xs) = consume s xs
consume s [] = null s
consume _ _ = False
main = getArgs &#62;&#62;= print . show . map (consume [])</description>
		<content:encoded><![CDATA[<p>import System(getArgs)<br />
consume s (&#8217;[':xs) = consume ('[':s) xs<br />
consume ('[':s) (']&#8216;:xs) = consume s xs<br />
consume s (&#8217;(':xs) = consume (&#8217;(':s) xs<br />
consume (&#8217;(':s) (&#8217;)':xs) = consume s xs<br />
consume s [] = null s<br />
consume _ _ = False<br />
main = getArgs &gt;&gt;= print . show . map (consume [])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-18998</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 10 Oct 2008 21:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-18998</guid>
		<description>Actually, the fact that you can post a neater solution was exactly the point, but that was lost a long time ago. The neater solution can be derived from the less neat solution by replacing lower-order expressions with higher-order expressions and kapoof! Let there be Parsec.</description>
		<content:encoded><![CDATA[<p>Actually, the fact that you can post a neater solution was exactly the point, but that was lost a long time ago. The neater solution can be derived from the less neat solution by replacing lower-order expressions with higher-order expressions and kapoof! Let there be Parsec.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krzysztof Kościuszkiewicz</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-18110</link>
		<dc:creator>Krzysztof Kościuszkiewicz</dc:creator>
		<pubDate>Sun, 05 Oct 2008 04:05:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-18110</guid>
		<description>I have to admit that your Haskell solution is far from being clear, and that doesn't help you with geting your main point across.

I'm posting a shorter and less dense solution to your problem below. Hope that helps :)

&lt;code&gt;
import Control.Monad
import System.Environment

tokens = [('[',']'), ('(',')')]

parse []     = Just []
parse (c:cs) = case lookup c tokens of
    Nothing  -&#62; return (c:cs)
    Just end -&#62; parse cs &#62;&#62;= consume end &#62;&#62;= parse

consume c []     = Nothing
consume c (x:xs) = guard (c == x) &#62;&#62; return xs

main = getArgs &#62;&#62;= mapM (print . maybe False null . parse)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I have to admit that your Haskell solution is far from being clear, and that doesn&#8217;t help you with geting your main point across.</p>
<p>I&#8217;m posting a shorter and less dense solution to your problem below. Hope that helps <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code><br />
import Control.Monad<br />
import System.Environment</p>
<p>tokens = [('[',']&#8216;), (&#8217;(',&#8217;)')]</p>
<p>parse []     = Just []<br />
parse (c:cs) = case lookup c tokens of<br />
    Nothing  -&gt; return (c:cs)<br />
    Just end -&gt; parse cs &gt;&gt;= consume end &gt;&gt;= parse</p>
<p>consume c []     = Nothing<br />
consume c (x:xs) = guard (c == x) &gt;&gt; return xs</p>
<p>main = getArgs &gt;&gt;= mapM (print . maybe False null . parse)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Shaw</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-16381</link>
		<dc:creator>Steven Shaw</dc:creator>
		<pubDate>Thu, 25 Sep 2008 06:02:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-16381</guid>
		<description>Here's my top-down parser version in Java.

&lt;pre&gt;
public class SimpleBraceParser {

  private int index = 0;
  private String s;

  public SimpleBraceParser(String s) { this.s = s; }

  private void skip(char c) {
    ++index;
  }

  private char currentChar() {
    if (index &#60; s.length()) return s.charAt(index);
    else return ''; // Evil "sentinel" value
  }

  private void eat(char c) {
    if (currentChar() == c) {
      ++index;
      return;
    }
    throw new RuntimeException("parse error at " + index + ", expecting '" + c + "'");
  }

  public void parseRoundBrace() {
    skip('(');
    parseExpr();
    eat(')');
  }

  public void parseSquareBracket() {
    skip('[');
    parseExpr();
    eat(']');
  }

  public boolean parseExpr() {
    if (currentChar() == '(') {
      parseRoundBrace();
      return true;
    } else if (currentChar() == '[') {
      parseSquareBracket();
      return true;
    } else return false;
  }

  public void parseExprs() {
    while (parseExpr()) {
    }
  }

  public void parse() {
    parseExprs();
    if (currentChar() != '') 
      throw new RuntimeException("not terminated correctly at " + index);
  }

  static boolean reportErrors = false;

  public static void main(String[] args) {
    for (String arg : args) {
      SimpleBraceParser p = new SimpleBraceParser(arg);
      try {
        p.parse();
        System.out.println("true");
      } catch (Exception e) {
        if (reportErrors) e.printStackTrace(System.err);
        System.out.println("false");
      }
    }
  }

}
&lt;/pre&gt;

Yep, it's pretty long! I like top-down parsers as they are pretty intuitive. I'd use Antlr for any more serious parser work.

I really like the look at the Haskell version with Parsec. I tested your Haskell, Scala and Java versions along with my Java version and the Parsec version (amongst others). Your Haskell version and Parsec are very fast - Parsec is faster :). I only used /usr/bin/time to test so the JVM startup time could have hampered the Java solutions. My recursive Java version and your Scala version require stack-size increases (on my large inputs).

With the Scala version performance extremely poorly on large inputs. Pretty sure it doesn't matter if the inputs are heavily nested or not. Maybe Scala isn't the best language for functional style code. Are there any ways to improve the performance and stay functional?</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my top-down parser version in Java.</p>
<pre>
public class SimpleBraceParser {

  private int index = 0;
  private String s;

  public SimpleBraceParser(String s) { this.s = s; }

  private void skip(char c) {
    ++index;
  }

  private char currentChar() {
    if (index &lt; s.length()) return s.charAt(index);
    else return ''; // Evil "sentinel" value
  }

  private void eat(char c) {
    if (currentChar() == c) {
      ++index;
      return;
    }
    throw new RuntimeException("parse error at " + index + ", expecting '" + c + "'");
  }

  public void parseRoundBrace() {
    skip('(');
    parseExpr();
    eat(')');
  }

  public void parseSquareBracket() {
    skip('[');
    parseExpr();
    eat(']');
  }

  public boolean parseExpr() {
    if (currentChar() == '(') {
      parseRoundBrace();
      return true;
    } else if (currentChar() == '[') {
      parseSquareBracket();
      return true;
    } else return false;
  }

  public void parseExprs() {
    while (parseExpr()) {
    }
  }

  public void parse() {
    parseExprs();
    if (currentChar() != '')
      throw new RuntimeException("not terminated correctly at " + index);
  }

  static boolean reportErrors = false;

  public static void main(String[] args) {
    for (String arg : args) {
      SimpleBraceParser p = new SimpleBraceParser(arg);
      try {
        p.parse();
        System.out.println("true");
      } catch (Exception e) {
        if (reportErrors) e.printStackTrace(System.err);
        System.out.println("false");
      }
    }
  }

}
</pre>
<p>Yep, it&#8217;s pretty long! I like top-down parsers as they are pretty intuitive. I&#8217;d use Antlr for any more serious parser work.</p>
<p>I really like the look at the Haskell version with Parsec. I tested your Haskell, Scala and Java versions along with my Java version and the Parsec version (amongst others). Your Haskell version and Parsec are very fast - Parsec is faster :). I only used /usr/bin/time to test so the JVM startup time could have hampered the Java solutions. My recursive Java version and your Scala version require stack-size increases (on my large inputs).</p>
<p>With the Scala version performance extremely poorly on large inputs. Pretty sure it doesn&#8217;t matter if the inputs are heavily nested or not. Maybe Scala isn&#8217;t the best language for functional style code. Are there any ways to improve the performance and stay functional?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul King</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-15975</link>
		<dc:creator>Paul King</dc:creator>
		<pubDate>Sat, 20 Sep 2008 15:12:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-15975</guid>
		<description>Groovy version of Bruce's solution:

def parse(s) { def t = s.replace("[]", "").replace("()", ""); t == s ? t : parse(t) }
args.each { println parse(it) == "" }

A little less imperative:

brackets = ["[]", "()"]
def parse2(s) { def t = brackets.inject(s){ a, b -&#62; a.replace(b,"") }; t == s ? t : parse2(t) }</description>
		<content:encoded><![CDATA[<p>Groovy version of Bruce&#8217;s solution:</p>
<p>def parse(s) { def t = s.replace(&#8221;[]&#8220;, &#8220;&#8221;).replace(&#8221;()&#8221;, &#8220;&#8221;); t == s ? t : parse(t) }<br />
args.each { println parse(it) == &#8220;&#8221; }</p>
<p>A little less imperative:</p>
<p>brackets = ["[]&#8220;, &#8220;()&#8221;]<br />
def parse2(s) { def t = brackets.inject(s){ a, b -&gt; a.replace(b,&#8221;") }; t == s ? t : parse2(t) }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnaud Bailly</title>
		<link>http://blog.tmorris.net/haskell-scala-java-7-functional-java-java/#comment-13695</link>
		<dc:creator>Arnaud Bailly</dc:creator>
		<pubDate>Tue, 09 Sep 2008 19:42:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=255#comment-13695</guid>
		<description>Hello, 
Thank you for the problem. I proposed it for yesterday's dojo in Paris and we have had a very interesting session. We came up with a simple solution based on replaceAll(), like one proposal among the preceding comments, except of course we did it TDD :-) An interesting point IMHO is that all of the people around the table (about 10) did manage to help making progress towards the solution, as they were not impaired by the syntax (java) nor the environment (Eclipse), beyond the first 10 minutes setup, although most of them were not coding in java daily. I regret to say we did not achieve the same "effectiveness" with Haskell, which seems to be quite hard to grasp for most people. 

Anyway, thanks again for this nice setting. Could you be a bit more clear about the composability issues you were aiming at ?</description>
		<content:encoded><![CDATA[<p>Hello,<br />
Thank you for the problem. I proposed it for yesterday&#8217;s dojo in Paris and we have had a very interesting session. We came up with a simple solution based on replaceAll(), like one proposal among the preceding comments, except of course we did it TDD <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> An interesting point IMHO is that all of the people around the table (about 10) did manage to help making progress towards the solution, as they were not impaired by the syntax (java) nor the environment (Eclipse), beyond the first 10 minutes setup, although most of them were not coding in java daily. I regret to say we did not achieve the same &#8220;effectiveness&#8221; with Haskell, which seems to be quite hard to grasp for most people. </p>
<p>Anyway, thanks again for this nice setting. Could you be a bit more clear about the composability issues you were aiming at ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

