<?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>thatmattbone.com &#187; haskell</title>
	<atom:link href="http://thatmattbone.com/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://thatmattbone.com</link>
	<description>let's ride bikes...</description>
	<lastBuildDate>Mon, 19 Jul 2010 03:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>const id 1 2</title>
		<link>http://thatmattbone.com/2007/12/const-id-1-2/</link>
		<comments>http://thatmattbone.com/2007/12/const-id-1-2/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 06:21:00 +0000</pubDate>
		<dc:creator>Matt Bone</dc:creator>
				<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://thatmattbone.com/?p=29</guid>
		<description><![CDATA[While playing around with the 99 problems in Haskell, I came across this function const that takes two arguments and returns the first without ever evaluating the second. For example: const 1 2 returns 1. Now that is straightforward enough, but then I noticed that: const id 1 2 returns 2, and, indeed const id [...]]]></description>
			<content:encoded><![CDATA[<p>While playing around with the <a href="http://haskell.org/haskellwiki/99_questions/">99 problems in Haskell</a>, I came across this function <span style="font-family: courier new;">const</span> that takes two arguments and returns the first without ever evaluating the second.  For example:</p>
<p><span style="font-family: courier new;">const 1 2</span></p>
<p>returns <span style="font-family: courier new;">1</span>. Now that is straightforward enough, but then I noticed that:</p>
<p><span style="font-family: courier new;">const id 1 2</span></p>
<p>returns <span style="font-family: courier new;">2</span>, and, indeed <span style="font-family: courier new;">const id x y</span> always returns<span style="font-family: courier new;"> y</span>.  I was confused.  <span style="font-family: courier new;">id</span> is the identity function and quite simply returns its argument untouched.  After some searching and thinking,  I realized how this works.  If we consider the example above, it turns out that <span style="font-family: courier new;">const id 1</span> discards the <span style="font-family: courier new;">1</span> and returns the <span style="font-family: courier new;">id</span> function.  This function(<span style="font-family: courier new;">id</span>) is then evaluated with the remaining argument, <span style="font-family: courier new;">2</span>, and, presto, we get <span style="font-family: courier new;">2</span> as the answer.  Tricky, but not exactly readable.  A more human friendly form is probably:</p>
<p><span style="font-family: courier new;">flip const 1 2</span></p>
<p>A simple description of the <a href="http://www.zvon.org/other/haskell/Outputprelude/flip_f.html">flip function</a> is here.  Hooray for first class functions and lazy evaluation!</p>
]]></content:encoded>
			<wfw:commentRss>http://thatmattbone.com/2007/12/const-id-1-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.806 seconds -->
