<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vincent Gable's Blog &#187; Haskell</title>
	<atom:link href="http://vgable.com/blog/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://vgable.com/blog</link>
	<description>my weblog.</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Never Start An Integer With 0</title>
		<link>http://vgable.com/blog/2009/09/11/never-start-an-integer-with-0/</link>
		<comments>http://vgable.com/blog/2009/09/11/never-start-an-integer-with-0/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 12:14:12 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Octal]]></category>
		<category><![CDATA[Programming Language Design]]></category>
		<category><![CDATA[Programming Style]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Smalltalk]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=389</guid>
		<description><![CDATA[When programming, never start an integer with 0. Most programming languages treat a decimal number that starts with 0 as octal (base-8). So x = 013; does not set x to 13. Instead x is 11, because 013 is interpreted as 138 not 1310. Languages with this quirk include: C, C++, Objective-C, Java, JavaScript, Perl, [...]]]></description>
			<content:encoded><![CDATA[<p>When programming, <strong>never start an integer with 0</strong>. <em>Most</em> programming languages treat a decimal number that starts with 0 as octal (base-8). So <code>x = 013;</code> does <em>not</em> set <code>x</code> to 13. Instead <code>x</code> is 11, because <code>013</code> is interpreted as 13<sub>8</sub> not 13<sub>10</sub>.</p>
<p>Languages with this quirk include: <a href="http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/hexoctal.html">C, C++, Objective-C</a>, <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html">Java</a>, <a href="http://www.amazon.com/gp/product/0596101996?ie=UTF8&#038;tag=vincgabl-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596101996">JavaScript</a>, <a href="http://perl.active-venture.com/pod/perlfaq4-datanumber.html">Perl</a>, <a href="http://www.ibm.com/developerworks/opensource/library/os-python1/">Python 3.0</a>, and <a href="http://docs.huihoo.com/ruby/ruby-man-1.4/syntax.html#numeric">Ruby</a>. If you add up the &#8220;<a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">market share</a>&#8221; of these languages, it comes out to above 50%, which is why I say <em>most</em> languages.</p>
<h3>&#8220;But I use {Smalltalk, Haskell, Lisp, etc.}&#8221;</h3>
<p>I&#8217;m jealous that you get to use such a nice language. However, it&#8217;s bad programming hygiene to pick up habits that are <em>dangerous</em> in common languages.</p>
<p>Now, I assume you wouldn&#8217;t write 7 as <code>007</code>, unless the leading zero(s) carried some extra meaning. There are cases where this clarity outweighs &#8220;cleanliness&#8221; (unless the code meant to be ported to a C-like language).</p>
<p>But you should at least be aware of this inter-lingual gotcha.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/09/11/never-start-an-integer-with-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Best Quicksort Ever</title>
		<link>http://vgable.com/blog/2009/05/31/the-best-quicksort-ever/</link>
		<comments>http://vgable.com/blog/2009/05/31/the-best-quicksort-ever/#comments</comments>
		<pubDate>Sun, 31 May 2009 06:59:02 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[College]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Quicksort]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/05/31/the-best-quicksort-ever/</guid>
		<description><![CDATA[The first time I saw this quicksort in Haskell was an eye opening moment, qsort [] = [] qsort (x:xs) = qsort (filter (&#60; x) xs) ++ [x] ++ qsort (filter (&#62;= x) xs) The first line reads: &#8220;When you sort an empty list ([]), the result is another empty list&#8221;. The second line reads: [...]]]></description>
			<content:encoded><![CDATA[<p>The first time I saw <a href="http://www.haskell.org/haskellwiki/Introduction#Ease_of_understanding">this quicksort in Haskell</a> was an eye opening moment,</p>
<blockquote>
<pre>
qsort []     = []
qsort (x:xs) = qsort (filter (&lt; x) xs) ++ [x] ++ qsort (filter (&gt;= x) xs)
</pre>
<p>The first line reads: &#8220;When you sort an empty list (<code>[]</code>), the result is another empty list&#8221;. The second line reads: &#8220;To sort a list whose first element is named <code>x</code> and the rest of which is named <code>xs</code>, sort the elements of <code>xs</code> that are less than <code>x</code>, sort the elements of <code>xs</code> that are greater than or equal to <code>x</code>, and concatenate (<code>++</code>) the results, with <code>x</code> sandwiched in the middle.&#8221;
</p></blockquote>
<p>The code is so concise, yet clear (even with cryptic variable names like <code>xs</code>). The day my professor wrote it on the whiteboard was the first time I internalized that there might be something good about the <em>alien</em> world of functional programming.</p>
<p>The biggest revelation to me was, <code>filter (&lt; x) xs</code> . It&#8217;s amazing that <code>(&lt; x)</code> builds a temporary, unnamed, function equivalent to C++,</p>
<pre>bool lessThanX(AnyOrderedType y){
    return y &lt; X;
}
//plus the definition of X somewhere...</pre>
<p><em>Building a function!</em> It&#8217;s still profound stuff to me. And <strong>clearly it really uses fewer lines of code</strong>. Amazingly, using <a href="http://en.wikipedia.org/wiki/List_comprehension">list comprehension</a> syntax is not more concise,</p>
<pre>qsort (x:xs) = qsort [i | i &lt;- xs, i &lt; x] ++ [x] ++ qsort [i | i &lt;- xs, i &lt;= x]</pre>
<p>compared to the original,</p>
<pre>qsort (x:xs) = qsort (filter (&lt; x) xs) ++ [x] ++ qsort (filter (&gt;= x) xs)</pre>
<p>I hope this is an <em>ah-ah</em> moment for someone else too. I&#8217;d love to know what made you interested in functional programming; or if you know of a more elegant quicksort implementation.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/05/31/the-best-quicksort-ever/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NP-Complete is Often Easy</title>
		<link>http://vgable.com/blog/2008/07/03/np-complete-is-often-easy/</link>
		<comments>http://vgable.com/blog/2008/07/03/np-complete-is-often-easy/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 00:55:13 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[NP-Complete]]></category>
		<category><![CDATA[NP-Hard]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2008/07/03/np-complete-is-often-easy/</guid>
		<description><![CDATA[There are a lot of problems that are, in theory, incredibly difficult &#8211; but because the difficult cases are very rare and rather contrived, they&#8217;re actually very easy to solve. Two examples of this that I find particularly interesting are both NP complete. Type checking in Haskell is one of them: in fact, the general [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p> There are a lot of problems that are, in theory, incredibly difficult &#8211; but because the difficult cases are very rare and rather contrived, they&#8217;re actually very easy to solve. Two examples of this that I find particularly interesting are both NP complete. Type checking in Haskell is one of them: in fact, the general type inference in Haskell is worse that NP complete: the type validation is NP-complete; type inference is NP-hard. But on real code, it&#8217;s effectively approximately linear. The other one is a logic problem called 3-SAT. I once attended a great talk by a guy named Daniel Jackson, talking about a formal specification language he&#8217;d designed called Alloy. Alloy reduces its specification checking to 3-SAT. Dan explained this saying: &#8220;The bad news is, analyzing Alloy specifications is 3-SAT, so it&#8217;s exponential and NP-complete. But the good news is that analyzing Alloy specifications is 3-SAT, so we can solve it really quickly</p></blockquote>
<p>&#8211;<a href="http://scienceblogs.com/goodmath/2008/05/linear_programming.php">Mark Chu-Carroll (aka MarkCC</a></p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2008/07/03/np-complete-is-often-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

