<?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>porges &#187; lisp</title>
	<atom:link href="http://porg.es/blog/tag/lisp/feed" rel="self" type="application/rss+xml" />
	<link>http://porg.es/blog</link>
	<description></description>
	<lastBuildDate>Thu, 12 Jan 2012 23:45:56 +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>Matching checklists using Haskell</title>
		<link>http://porg.es/blog/matching-checklists-using-haskell</link>
		<comments>http://porg.es/blog/matching-checklists-using-haskell#comments</comments>
		<pubDate>Wed, 23 Jan 2008 08:52:55 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[replies]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://porg.es/blog/matching-checklists-using-haskell</guid>
		<description><![CDATA[Our target for this exercise is “Things that other languages should take from Lisp”. Bignum support In Scheme and Common Lisp, by default you can&#8217;t overflow an integer&#8230; Prelude&#62; fac n = product &#91;2..n&#93; Prelude&#62; fac 100 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582 51185210916864000000000000000000000000 In Common Lisp, you can force your code to use fixed-size numbers (fixnums) for efficiency&#8230; Prelude&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Our target for this exercise is “<a href="http://repinvariant.blogspot.com/2008/01/thoughts-on-lisp-things-that-other.html">Things that other languages should take from Lisp</a>”.</p>
<h3>Bignum support</h3>
<blockquote><p>In Scheme and Common Lisp, by default you can&#8217;t overflow an integer&#8230;</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> fac n <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">product</span> <span style="color: green;">&#91;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">..</span>n<span style="color: green;">&#93;</span>
Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> fac <span style="color: red;">100</span>
<span style="color: red;">933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582</span>
<span style="color: red;">51185210916864000000000000000000000000</span></pre></div></div>

<blockquote><p>In Common Lisp, you can force your code to use fixed-size numbers (fixnums) for efficiency&#8230;</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">let</span> fac n <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">product</span> <span style="color: green;">&#91;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">..</span>n<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Int</span>
Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> fac <span style="color: red;">17</span>
<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">288522240</span></pre></div></div>

<blockquote><p>Ruby and Python, by default, treat language-integers as logical-integers. Java, C, C++, and Perl don&#8217;t.</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> :t <span style="color: red;">15</span>
<span style="color: red;">15</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> t</pre></div></div>

<h3>Optional type declarations</h3>
<blockquote><p>[Common Lisp] allows, but does not require, type declarations.</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">let</span> doubleApply f x <span style="color: #339933; font-weight: bold;">=</span> f <span style="color: green;">&#40;</span>f x<span style="color: green;">&#41;</span>
Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> :t doubleApply
doubleApply <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span>t <span style="color: #339933; font-weight: bold;">-&gt;</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> t <span style="color: #339933; font-weight: bold;">-&gt;</span> t</pre></div></div>

<blockquote><p>The compiler can also use type declarations to perform compile-time typechecking. (Sadly, it isn&#8217;t <em>required</em> to do this.)</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> doubleApply <span style="color: red;">3</span> doubleApply
&nbsp;
<span style="color: #339933; font-weight: bold;">&lt;</span>interactive<span style="color: #339933; font-weight: bold;">&gt;</span>:<span style="color: red;">1</span>:<span style="color: red;">12</span>:
    No <span style="color: #06c; font-weight: bold;">instance</span> for <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>t <span style="color: #339933; font-weight: bold;">-&gt;</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> t <span style="color: #339933; font-weight: bold;">-&gt;</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>t <span style="color: #339933; font-weight: bold;">-&gt;</span> t<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> t <span style="color: #339933; font-weight: bold;">-&gt;</span> t<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
      arising from the literal `<span style="color: red;">3</span>' at <span style="color: #339933; font-weight: bold;">&lt;</span>interactive<span style="color: #339933; font-weight: bold;">&gt;</span>:<span style="color: red;">1</span>:<span style="color: red;">12</span></pre></div></div>

<h3>Tail recursion</h3>
<blockquote><p>Proper (unbounded) tail-recursion (Scheme.)</p>
</blockquote>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: #06c; font-weight: bold;">let</span> loop <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: green;">&#123;</span> <span style="font-weight: bold;">putStr</span> <span style="background-color: #3cb371;">&quot;.&quot;</span>; loop <span style="color: green;">&#125;</span>
Prelude<span style="color: #339933; font-weight: bold;">&gt;</span> loop
<span style="color: #339933; font-weight: bold;">......................................</span>
<span style="color: #339933; font-weight: bold;">......................................</span>
<span style="color: green;">&#91;</span>etc<span style="color: green;">&#93;</span>
<span style="color: #339933; font-weight: bold;">......................................</span>
<span style="color: #339933; font-weight: bold;">..........................</span>Interrupted<span style="color: #339933; font-weight: bold;">.</span></pre></div></div>

<p>(But see <a href="http://www.haskell.org/haskellwiki/Stack_overflow">the Haskell wiki</a>. Laziness introduces a small trick here.)</p>
<h3>Functions which depend upon the type of multiple arguments</h3>
<blockquote><p>Methods with multiple-dispatch (Common Lisp.)</p>
</blockquote>
<p>(This doesn’t <em>exactly</em> match conceptually because Haskell doesn’t have nominal overloading.)</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">multi Nothing Nothing <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">0</span>
multi <span style="color: green;">&#40;</span>Just x<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Just y<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> x <span style="color: #339933; font-weight: bold;">+</span> y
multi Nothing <span style="color: green;">&#40;</span>Just y<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> y
multi <span style="color: green;">&#40;</span>Just x<span style="color: green;">&#41;</span> Nothing <span style="color: #339933; font-weight: bold;">=</span> x</pre></div></div>

<h3>Fast implementations</h3>
<blockquote><p>Some Lisp implementations are fast.</p>
</blockquote>
<p><a href="http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&amp;lang=all&amp;xfullcpu=1&amp;xmem=0&amp;xloc=0&amp;binarytrees=1&amp;chameneosredux=1&amp;fannkuch=1&amp;fasta=1&amp;knucleotide=1&amp;mandelbrot=1&amp;meteor=1&amp;nbody=1&amp;nsieve=1&amp;nsievebits=1&amp;partialsums=1&amp;pidigits=1&amp;recursive=1&amp;regexdna=1&amp;revcomp=1&amp;spectralnorm=1&amp;hello=1&amp;sumcol=1&amp;threadring=1&amp;calc=Calculate">Haskell  #7 on the Great Language Shootout</a> (in terms of speed), and getting faster by the day as the backend of GHC is rewritten.</p>
<h3>Syntactic Simplicity</h3>
<blockquote><p>Syntactic simplicity (Scheme.)</p>
</blockquote>
<p><a href="http://haskell.org/onlinereport/syntax-iso.html#sect9.5">The Haskell <abbr title="Context-Free Grammar">CFG</abbr>.</a></p>
<blockquote><p>Or perhaps Python is another incarnation of syntactic simplicity.</p>
</blockquote>
<p><a href="http://haskell.org/onlinereport/lexemes.html#lexemes-layout">The Layout Rule</a></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/matching-checklists-using-haskell/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

