<?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/"
	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>Brandon Niemczyk's Stuff</title>
	<atom:link href="http://bniemczyk.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bniemczyk.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 22 Jan 2009 13:55:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bniemczyk.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brandon Niemczyk's Stuff</title>
		<link>http://bniemczyk.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bniemczyk.wordpress.com/osd.xml" title="Brandon Niemczyk&#039;s Stuff" />
	<atom:link rel='hub' href='http://bniemczyk.wordpress.com/?pushpress=hub'/>
		<item>
		<title>IoC, Functional Programming, and DSLs</title>
		<link>http://bniemczyk.wordpress.com/2009/01/21/47/</link>
		<comments>http://bniemczyk.wordpress.com/2009/01/21/47/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 22:41:33 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[design patterns]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=47</guid>
		<description><![CDATA[The Inversion of Control (IoC) design pattern, functional programming, and Domain Specific Languages are all different faces of the same underlying concept and can be used interchangeably.  Recognizing this should make it easier to understand each one and when they should be used within your own code. IoC simply refers to a library passing control [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=47&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <strong>Inversion of Control</strong> (IoC) design pattern, <strong>functional programming</strong>, and <strong>Domain Specific Languages</strong> are all different faces of the same underlying concept and can be used interchangeably.  Recognizing this should make it easier to understand each one and when they should be used within your own code.</p>
<p>IoC simply refers to a library passing control to it&#8217;s caller.  A typical object-oriented implementation would be a function which takes an object that implements ISomething where ISomething has a single method that the function then calls.  Those familiar with the <strong>visitor</strong> pattern should recognize that the visitor pattern is just a specialization of IoC where the callers code is applied to each object in a collection (actually any structure, it doesn&#8217;t *have* to be a collection).</p>
<p>I think the tie between IoC and functional programming should be pretty obvious at this point.  If your language supports <strong>first class functions</strong> and <strong>closures</strong>, then creating an interface with a single method is just extra work when you can simply pass a function as a parameter.   In fact, since a closure will close over lexical variables to maintain their &#8220;state&#8221;, both types of IoC implementation (Interfaces and Functions) are exactly equivelant in terms of power.  I believe that using a simple function is more readable though, and it&#8217;s certainly more convienent for the caller to not have to create a class that implements ISomething.</p>
<p>The tie between DSLs and IoC is more abstract and requires exploration into the problems being solved.  IoC is a useful design when the problem is not completely specified.  If you are writing a library and the only thing that will vary in how it&#8217;s used is the inputs, IoC is just extra typing with no real benefit.  If your problem is only partially specified on the other hand, then IoC allows you to implement the bits of the solution that you can infer from the specs, and leave the rest up to the caller.  This is why very generic libraries tend to use IoC a lot.  A DSL typically provides the users with a base set of <strong>combinators</strong> (functions that create functions out of other functions) to build up functions that perform a specific type of task in a very high level manner.  A DSL for writing parsers should look very close to <strong>BNF</strong> so that a grammar can be encoded in the host language with as few implementation specific details as possible.  How to do this with combinators is an interesting topic itself that deserves it&#8217;s own post and maybe I will get motivated and write one some day.  A more intuitive example is configuration files, any time you have a configuration file that can change the flow of a program you are creating a mini-language and you are passing control to the end-user (ie.. IoC).</p>
<p>So great, they are the same thing conceptually, what do we gain from this?  Well we can transfer the knowledge we have from one paradigm (like OO) to another (like functional) and vice versa.  More concretely, by recognizing that they are all ways to <strong>partially</strong> specify a solution, we now have a good solid concrete criteria for deciding when one of these types of implementation are necessary.</p>
<p>On a side note, this should help highlight the difference between a pattern and an implementation.  Interfaces/Functions/Monads are ways to implement the IoC pattern.  Creating a library to &#8220;handle IoC&#8221; is confusing the two, and if you find yourself writing or consuming one of these libraries, then some reflection on how your handling the task at hand would probably do some good.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=47&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2009/01/21/47/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>5 reasons to use Git instead of Subversion</title>
		<link>http://bniemczyk.wordpress.com/2008/12/11/5-reasons-to-use-git-instead-of-subversion/</link>
		<comments>http://bniemczyk.wordpress.com/2008/12/11/5-reasons-to-use-git-instead-of-subversion/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 14:12:59 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[version control systems]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=41</guid>
		<description><![CDATA[Git is a new version control system originally written and designed by Linus Torvalds for managing the development of the Linux kernel.  Due to the chaotic nature and massive amout of contributers to Linux kernel development, Linus is quite arguably the most qualified person in the world to design a good VCS.  Git is quite [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=41&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Git is a new version control system originally written and designed by Linus Torvalds for managing the development of the Linux kernel.  Due to the chaotic nature and massive amout of contributers to Linux kernel development, Linus is quite arguably the most qualified person in the world to design a good VCS.  Git is quite a bit different than a traditional VCS such as Subversion and it doesn&#8217;t have the mathematical theory that darcs has behind it, but it is by far the most <strong>practical</strong> VCS I have used to date.  So anyways, here are my 5 favorite reasons to git.</p>
<ol>
<li>You always have a full copy of the repository with all the meta-data, online or off</li>
<li>You can merge with anybody&#8217;s repository, not only a single central server</li>
<li>Even with the full history, git repositories take less space than a SVN checkout
<pre>brandon@Brandon:~/localtmp/clone$ du -sh *
1.6G    cohiba.git
2.6G    cohiba.svn</pre>
</li>
<li>Modifying the history is easy, using git rebase -i &lt;some_revision&gt; will bring up a list of patches in your favorite editor and allow you to merge/reorder/delete them, then it will apply them as you&#8217;ve specified, re-committing with each one
<pre>pick e4eb2ca Added -d option to only look at 1 date
pick 881ef7f Fixed bug that caused an Prelude.head: empty list exception if no work orders were pushed
pick 3595183 Added line itemized reports on pushed work orders
pick 1b6ff52 Fixed the parser so that it doesn't break if there is a [] in the stack trace It was using a bit of a hack, but i've cleaned up the parser so there should be no more suprises, no matter what we throw at it
pick 12b7023 Changed slurp_until to fail on eof
pick e511b15 New log file for tests

# Rebase 378dd8b..e511b15 onto 378dd8b
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.</pre>
</li>
<li>You don&#8217;t need a centralized server with a single &#8216;master&#8217; copy of the codebase with git, but that is  still how most software shops will operate.  Any mucking with this master copy would be noticed by all because git revision id&#8217;s are hash sums of the entire history up to that point.</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=41&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/12/11/5-reasons-to-use-git-instead-of-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>bnIRC 1.0 released</title>
		<link>http://bniemczyk.wordpress.com/2008/11/30/bnirc-10-released/</link>
		<comments>http://bniemczyk.wordpress.com/2008/11/30/bnirc-10-released/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 19:58:35 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[bnirc]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=37</guid>
		<description><![CDATA[I&#8217;ve finally released a 1.0 version of bnIRC.  It&#8217;s available on sourceforge as a .deb or a source package.  Windows builds are planned but will have to wait until a future release, hopefully not too far out.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=37&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally released a 1.0 version of bnIRC.  It&#8217;s available on <a href="http://sourceforge.net/projects/bnirc">sourceforge</a> as a .deb or a source package.  Windows builds are planned but will have to wait until a future release, hopefully not too far out.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=37&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/11/30/bnirc-10-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>New life in bnIRC</title>
		<link>http://bniemczyk.wordpress.com/2008/10/25/new-life-in-bnirc/</link>
		<comments>http://bniemczyk.wordpress.com/2008/10/25/new-life-in-bnirc/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 19:26:29 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[bnirc]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=32</guid>
		<description><![CDATA[I&#8217;ve decided to breath some new life into my IRC client. I&#8217;m using a few people on freenode to test test test so that I can make it stable. The goal is to have a rock-solid (no new features) 1.0 release within the next few weeks and afterwards I&#8217;ll be adding some features that have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=32&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to breath some new life into my IRC client.  I&#8217;m using a few people on freenode to test test test so that I can make it stable.  The goal is to have a rock-solid (no new features) 1.0 release within the next few weeks and afterwards I&#8217;ll be adding some features that have been requested.</p>
<p>I created a git repot on github.com.  Tarballs/zip files can be downloaded <a href="http://github.com/bniemczyk/bnirc/tree/master">here</a>.  Or if you have git installed you can run:</p>
<p>git clone git://github.com/bniemczyk/bnirc.git</p>
<p>If your interested in helping test please do!  Make sure that the python and ncurses header files (python-dev and ncurses-dev on debian) are installed before you run ./configure, or you&#8217;ll get a very bare-bones interface that is really only meant for debugging.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=32&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/10/25/new-life-in-bnirc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick and dirty intro to Lambda Calculus &#8211; Post #3</title>
		<link>http://bniemczyk.wordpress.com/2008/10/25/quick-and-dirty-intro-to-lambda-calculus-post-3/</link>
		<comments>http://bniemczyk.wordpress.com/2008/10/25/quick-and-dirty-intro-to-lambda-calculus-post-3/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 19:18:26 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[lambda calculus]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=13</guid>
		<description><![CDATA[This is a continuation of my previous post. In order for -Calculus to be useful, we have to be able to encode data. In our previous post we used integers and booleans without any explanation as to how they may be encoded. This picks up and fills out those details. Booleans It is useful to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=13&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a continuation of my <a href="http://bniemczyk.wordpress.com/2008/10/20/quick-and-dirty-intro-to-lambda-calculus-post-2/">previous post</a>.</p>
<p>In order for <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus to be useful, we have to be able to encode data.  In our previous post we used integers and booleans without any explanation as to how they may be encoded.  This picks up and fills out those details.</p>
<p><strong>Booleans</strong></p>
<p>It is useful to encode boolean values as functions that take 2 parameters and then evalute the correct argument.</p>
<p><img src='http://s0.wp.com/latex.php?latex=T+%5Cequiv+%5Ctext%7BTrue+%7D+%5Cequiv+%5Clambda+xy+.+x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T &#92;equiv &#92;text{True } &#92;equiv &#92;lambda xy . x' title='T &#92;equiv &#92;text{True } &#92;equiv &#92;lambda xy . x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=F+%5Cequiv+%5Ctext%7BFalse+%7D+%5Cequiv+%5Clambda+xy+.+y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='F &#92;equiv &#92;text{False } &#92;equiv &#92;lambda xy . y' title='F &#92;equiv &#92;text{False } &#92;equiv &#92;lambda xy . y' class='latex' /></p>
<p>Assuming we have a boolean <img src='http://s0.wp.com/latex.php?latex=P&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P' title='P' class='latex' /> we can encode an <strong>if-then-else</strong> function as <img src='http://s0.wp.com/latex.php?latex=PAB&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='PAB' title='PAB' class='latex' /> where <img src='http://s0.wp.com/latex.php?latex=A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='A' title='A' class='latex' /> is the result if <img src='http://s0.wp.com/latex.php?latex=P+%5Cequiv+T&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P &#92;equiv T' title='P &#92;equiv T' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B' title='B' class='latex' /> is the result if <img src='http://s0.wp.com/latex.php?latex=P+%5Cequiv+F&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='P &#92;equiv F' title='P &#92;equiv F' class='latex' /> ie..</p>
<p><img src='http://s0.wp.com/latex.php?latex=TAB+%5Cequiv+A&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='TAB &#92;equiv A' title='TAB &#92;equiv A' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=FAB+%5Cequiv+B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='FAB &#92;equiv B' title='FAB &#92;equiv B' class='latex' /></p>
<p><strong>Church Numerals</strong></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BZero+%7D+%5Cequiv+%5Clambda+fx+.+x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Zero } &#92;equiv &#92;lambda fx . x' title='&#92;text{Zero } &#92;equiv &#92;lambda fx . x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=1+%5Cequiv+%5Clambda+fx+.+fx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1 &#92;equiv &#92;lambda fx . fx' title='1 &#92;equiv &#92;lambda fx . fx' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=2+%5Cequiv+%5Clambda+fx+.+ffx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2 &#92;equiv &#92;lambda fx . ffx' title='2 &#92;equiv &#92;lambda fx . ffx' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=3+%5Cequiv+%5Clambda+fx+.+fffx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='3 &#92;equiv &#92;lambda fx . fffx' title='3 &#92;equiv &#92;lambda fx . fffx' class='latex' /></p>
<p>&#8230;</p>
<p><img src='http://s0.wp.com/latex.php?latex=n+%5Cequiv+%5Clambda+fx+.+f%5Enx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n &#92;equiv &#92;lambda fx . f^nx' title='n &#92;equiv &#92;lambda fx . f^nx' class='latex' /></p>
<p>And now to show the basic operations on numerals</p>
<p><em>Increment</em></p>
<p><em><span style="font-weight:normal;"><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BInc+%7D+%5Cequiv+%5Clambda+nfx+.+f+%28nfx%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Inc } &#92;equiv &#92;lambda nfx . f (nfx)' title='&#92;text{Inc } &#92;equiv &#92;lambda nfx . f (nfx)' class='latex' /></span></em></p>
<p>Example :</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BInc+Zero+%7D+%5Cequiv+%5Clambda+nfx+.+f+%28nfx%29+%5Bn+%3A%3D+%5Ctext%7BZero%7D%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Inc Zero } &#92;equiv &#92;lambda nfx . f (nfx) [n := &#92;text{Zero}]' title='&#92;text{Inc Zero } &#92;equiv &#92;lambda nfx . f (nfx) [n := &#92;text{Zero}]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+f+%28%5Ctext%7BZero+%7D+f+x%29+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . f (&#92;text{Zero } f x) ' title='&#92;equiv &#92;lambda fx . f (&#92;text{Zero } f x) ' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+f+%28%28%5Clambda+fx+.+x%29+f+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . f ((&#92;lambda fx . x) f x)' title='&#92;equiv &#92;lambda fx . f ((&#92;lambda fx . x) f x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+f+x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . f x' title='&#92;equiv &#92;lambda fx . f x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv 1' title='&#92;equiv 1' class='latex' /></p>
<p><em>Decrement</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BDec+%7D+%5Cequiv+%5Clambda+nfx+.+n+%28%5Clambda+gh+.+h+%28g+f%29%29+%28%5Clambda+u+.+x%29+%28%5Clambda+u+.+u%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Dec } &#92;equiv &#92;lambda nfx . n (&#92;lambda gh . h (g f)) (&#92;lambda u . x) (&#92;lambda u . u)' title='&#92;text{Dec } &#92;equiv &#92;lambda nfx . n (&#92;lambda gh . h (g f)) (&#92;lambda u . x) (&#92;lambda u . u)' class='latex' /></p>
<p>Example:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BDec+%7D+1+%5Cequiv+%5Clambda+nfx+.+n+%28%5Clambda+gh+.+h+%28gf%29%29+%28%5Clambda++u+.+x%29+%28%5Clambda+u+.+u%29+%5Bn+%3A%3D+%5Clambda+fx+.+fx%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Dec } 1 &#92;equiv &#92;lambda nfx . n (&#92;lambda gh . h (gf)) (&#92;lambda  u . x) (&#92;lambda u . u) [n := &#92;lambda fx . fx]' title='&#92;text{Dec } 1 &#92;equiv &#92;lambda nfx . n (&#92;lambda gh . h (gf)) (&#92;lambda  u . x) (&#92;lambda u . u) [n := &#92;lambda fx . fx]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+%28%5Clambda+fx+.+fx%29+%28%5Clambda+gh+.+h+%28gf%29%29+%28%5Clambda+u+.+x%29+%28%5Clambda+u+.+u%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . (&#92;lambda fx . fx) (&#92;lambda gh . h (gf)) (&#92;lambda u . x) (&#92;lambda u . u)' title='&#92;equiv &#92;lambda fx . (&#92;lambda fx . fx) (&#92;lambda gh . h (gf)) (&#92;lambda u . x) (&#92;lambda u . u)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+%28%5Clambda+x+.+%28%5Clambda+gh+.+h+%28gf%29%29+x%29+%28%5Clambda+u+.+x%29+%28%5Clambda+u+.+u%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . (&#92;lambda x . (&#92;lambda gh . h (gf)) x) (&#92;lambda u . x) (&#92;lambda u . u)' title='&#92;equiv &#92;lambda fx . (&#92;lambda x . (&#92;lambda gh . h (gf)) x) (&#92;lambda u . x) (&#92;lambda u . u)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+%28%5Clambda+x+.+%28%5Clambda+gh+.+h+%28gf%29%29+%28%5Clambda+u+.+x%29%29+%28%5Clambda+u+.+u%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . (&#92;lambda x . (&#92;lambda gh . h (gf)) (&#92;lambda u . x)) (&#92;lambda u . u)' title='&#92;equiv &#92;lambda fx . (&#92;lambda x . (&#92;lambda gh . h (gf)) (&#92;lambda u . x)) (&#92;lambda u . u)' class='latex' /></p>
<p><em>Addition</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BAdd+%7D+%5Cequiv+n+%2B+m+%5Cequiv+%5Clambda+mnfx+.+m+f+%28n+f+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Add } &#92;equiv n + m &#92;equiv &#92;lambda mnfx . m f (n f x)' title='&#92;text{Add } &#92;equiv n + m &#92;equiv &#92;lambda mnfx . m f (n f x)' class='latex' /></p>
<p>Example:</p>
<p><img src='http://s0.wp.com/latex.php?latex=1+%2B+1+%5Cequiv+%5Clambda+mnfx+.+m+f+%28n+f+x%29%5Bm+%3A%3D+1%5D%5Bn+%3A%3D+1%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1 + 1 &#92;equiv &#92;lambda mnfx . m f (n f x)[m := 1][n := 1]' title='1 + 1 &#92;equiv &#92;lambda mnfx . m f (n f x)[m := 1][n := 1]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+%28%5Clambda+fx.fx%29+f+%28%28%5Clambda+fx.fx%29+f+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . (&#92;lambda fx.fx) f ((&#92;lambda fx.fx) f x)' title='&#92;equiv &#92;lambda fx . (&#92;lambda fx.fx) f ((&#92;lambda fx.fx) f x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+%28%5Clambda+fx.fx%29+f+%28fx%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . (&#92;lambda fx.fx) f (fx)' title='&#92;equiv &#92;lambda fx . (&#92;lambda fx.fx) f (fx)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+ffx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . ffx' title='&#92;equiv &#92;lambda fx . ffx' class='latex' /></p>
<p>We can show that <img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BInc+%7D+%5Cequiv+%5Ctext%7BAdd+%7D+1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Inc } &#92;equiv &#92;text{Add } 1' title='&#92;text{Inc } &#92;equiv &#92;text{Add } 1' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BAdd+%7D+1+%5Cequiv+%5Clambda+mnfx+.+m+f+%28n+f+x%29+%5Bm+%3A%3D+%5Clambda+f+.+fx%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Add } 1 &#92;equiv &#92;lambda mnfx . m f (n f x) [m := &#92;lambda f . fx]' title='&#92;text{Add } 1 &#92;equiv &#92;lambda mnfx . m f (n f x) [m := &#92;lambda f . fx]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+nfx+.+%28%5Clambda+f+.+fx%29+f+%28n+f+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda nfx . (&#92;lambda f . fx) f (n f x)' title='&#92;equiv &#92;lambda nfx . (&#92;lambda f . fx) f (n f x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+nfx+.+f+%28n+f+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda nfx . f (n f x)' title='&#92;equiv &#92;lambda nfx . f (n f x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Ctext%7BInc+%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;text{Inc }' title='&#92;equiv &#92;text{Inc }' class='latex' /></p>
<p><em>Multiplication</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=m+%2A+n+%5Cequiv+%5Clambda+mnf+.+n+%28m+f%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='m * n &#92;equiv &#92;lambda mnf . n (m f)' title='m * n &#92;equiv &#92;lambda mnf . n (m f)' class='latex' /></p>
<p>Example:</p>
<p><img src='http://s0.wp.com/latex.php?latex=2+%2A+3+%5Cequiv+%5Clambda+mnf+.+n+%28m+f%29%5Bm+%3A%3D+2%5D%5Bn+%3A%3D+3%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2 * 3 &#92;equiv &#92;lambda mnf . n (m f)[m := 2][n := 3]' title='2 * 3 &#92;equiv &#92;lambda mnf . n (m f)[m := 2][n := 3]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+f+.+%28%5Clambda+fx.+f%5E3x%29+%28%28%5Clambda+fx+.+f%5E2x%29+f%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda f . (&#92;lambda fx. f^3x) ((&#92;lambda fx . f^2x) f)' title='&#92;equiv &#92;lambda f . (&#92;lambda fx. f^3x) ((&#92;lambda fx . f^2x) f)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+f+.+%28%5Clambda+fx+.+f%5E3x%29+%28%5Clambda+x.+f%5E2x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda f . (&#92;lambda fx . f^3x) (&#92;lambda x. f^2x)' title='&#92;equiv &#92;lambda f . (&#92;lambda fx . f^3x) (&#92;lambda x. f^2x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+f+.+%28%5Clambda+x+.+f%5E6+x%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda f . (&#92;lambda x . f^6 x)' title='&#92;equiv &#92;lambda f . (&#92;lambda x . f^6 x)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+fx+.+f%5E6+x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda fx . f^6 x' title='&#92;equiv &#92;lambda fx . f^6 x' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+6&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv 6' title='&#92;equiv 6' class='latex' /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=13&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/10/25/quick-and-dirty-intro-to-lambda-calculus-post-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick and dirty intro to Lambda Calculus &#8211; Post #2</title>
		<link>http://bniemczyk.wordpress.com/2008/10/20/quick-and-dirty-intro-to-lambda-calculus-post-2/</link>
		<comments>http://bniemczyk.wordpress.com/2008/10/20/quick-and-dirty-intro-to-lambda-calculus-post-2/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 13:32:48 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[lambda calculus]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=19</guid>
		<description><![CDATA[This is a continuatin of my previous post. In this post and all the following posts I write, all -calculus expressions are left-associative, ie.. In this post I will expound upon some of the things I glossed over in the last post. Variable Bindings The operator binds a variable. If a variable occurs in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=19&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a continuatin of my <a href="http://bniemczyk.wordpress.com/2008/10/17/quick-and-dirty-intro-to-lambda-calculus-post-1/">previous post</a>.</p>
<p><em>In this post and all the following posts I write, all <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-calculus expressions are left-associative, ie..</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=ABCD+%3D+%28%28AB%29C%29D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='ABCD = ((AB)C)D' title='ABCD = ((AB)C)D' class='latex' /></p>
<p>In this post I will expound upon some of the things I glossed over in the last post.</p>
<p><strong>Variable Bindings</strong></p>
<p>The <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' /> operator <em>binds</em> a variable.  If a variable occurs in the body of an abstraction but is not bound, then it is called <em>free</em>.  In the case of name clashes, variable <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> is bound to the inner most <img src='http://s0.wp.com/latex.php?latex=%5Clambda+x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x' title='&#92;lambda x' class='latex' />.</p>
<p><em><img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' />-conversion</em></p>
<p>The easiest way to ensure that variable names don&#8217;t have scope issues is to simply rename all bound variables to a unique name:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+%5Clambda+x+.+%28%5Clambda+x+.+x%29+x+%5Cequiv+%5Clambda+x_1+.+%5Clambda+x_2+.+%28%5Clambda+x_3+.+x_3%29+x_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . &#92;lambda x . (&#92;lambda x . x) x &#92;equiv &#92;lambda x_1 . &#92;lambda x_2 . (&#92;lambda x_3 . x_3) x_2' title='&#92;lambda x . &#92;lambda x . (&#92;lambda x . x) x &#92;equiv &#92;lambda x_1 . &#92;lambda x_2 . (&#92;lambda x_3 . x_3) x_2' class='latex' /></p>
<p><strong><img src='http://s0.wp.com/latex.php?latex=%5Cbeta&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />-reduction</strong></p>
<p>What I referred to as <em>simplifying</em> in the last post was actually a <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />-reduction.  <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />-reduction is the act of making all the applications in an expression that do not use any bound variables.  If all bound variables in expression have unique names, then a beta-reduction is very simple:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%28%5Clambda+A+.+B%29+B&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(&#92;lambda A . B) B' title='(&#92;lambda A . B) B' class='latex' /> reduces to <img src='http://s0.wp.com/latex.php?latex=B%5BA+%3A%3D+B%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='B[A := B]' title='B[A := B]' class='latex' /></p>
<p>The <img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' />-conversion described above is very important because if variable names clash, then a <img src='http://s0.wp.com/latex.php?latex=%5Cbeta&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;beta' title='&#92;beta' class='latex' />-reduction is much more complicated.  Take the following term:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%28%5Clambda+ab+.+ab%29+%28cb%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(&#92;lambda ab . ab) (cb)' title='(&#92;lambda ab . ab) (cb)' class='latex' /></p>
<p>Without first applying an <img src='http://s0.wp.com/latex.php?latex=%5Calpha&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;alpha' title='&#92;alpha' class='latex' />-conversion we might end up with something like this:</p>
<p><em>wrong:</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+ab+.+ab+%5Ba+%3A%3D+cb%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda ab . ab [a := cb]' title='&#92;lambda ab . ab [a := cb]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+b+.+%28cb%29+b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda b . (cb) b' title='&#92;equiv &#92;lambda b . (cb) b' class='latex' /></p>
<p>Now our free variable <img src='http://s0.wp.com/latex.php?latex=b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='b' title='b' class='latex' /> in <img src='http://s0.wp.com/latex.php?latex=%28cb%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(cb)' title='(cb)' class='latex' /> is incorrectly bound.  Instead we should get this:</p>
<p><em>correct:</em></p>
<p><img src='http://s0.wp.com/latex.php?latex=%28%5Clambda+ab+.+ab%29+%28cb%29+%5Cequiv+%28%5Clambda+a_1+b_1+.+a_1+b_1%29+%28c_1+b_2%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(&#92;lambda ab . ab) (cb) &#92;equiv (&#92;lambda a_1 b_1 . a_1 b_1) (c_1 b_2)' title='(&#92;lambda ab . ab) (cb) &#92;equiv (&#92;lambda a_1 b_1 . a_1 b_1) (c_1 b_2)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+a_1+b_1+.+a_1+b_1+%5B+a_1+%3A%3D+c_1+b_2+%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda a_1 b_1 . a_1 b_1 [ a_1 := c_1 b_2 ]' title='&#92;equiv &#92;lambda a_1 b_1 . a_1 b_1 [ a_1 := c_1 b_2 ]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cequiv+%5Clambda+b_1+.+%28c_1+b_2%29+b_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;equiv &#92;lambda b_1 . (c_1 b_2) b_1' title='&#92;equiv &#92;lambda b_1 . (c_1 b_2) b_1' class='latex' /></p>
<p>Now our newly renamed <img src='http://s0.wp.com/latex.php?latex=b_2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='b_2' title='b_2' class='latex' /> is still a free variable.</p>
<p>That&#8217;s it for this post, in an upcoming post I will explain how to encode some basic datatypes using pure <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-calculus.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=19&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/10/20/quick-and-dirty-intro-to-lambda-calculus-post-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick and dirty intro to Lambda Calculus &#8211; Post #1</title>
		<link>http://bniemczyk.wordpress.com/2008/10/17/quick-and-dirty-intro-to-lambda-calculus-post-1/</link>
		<comments>http://bniemczyk.wordpress.com/2008/10/17/quick-and-dirty-intro-to-lambda-calculus-post-1/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 20:55:41 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[functional programming]]></category>
		<category><![CDATA[lambda calculus]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/?p=7</guid>
		<description><![CDATA[This is the first of a multi-part post about -Calculus.  I&#8217;m going to start with a description of the Untyped -Calculus.  Future articles will include Church Numerals and Typed -Calculus. Why? -Calculus is important because it has a close tie with functional programming.  In fact most functional languages compile to some form of -Calculus.  You [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=7&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the first of a multi-part post about <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus.  I&#8217;m going to start with a description of the Untyped <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus.  Future articles will include Church Numerals and Typed <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus.</p>
<p><strong>Why?</strong></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus is important because it has a close tie with functional programming.  In fact most functional languages compile to some form of <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus.  You could say that <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus is to functional programming what the Turing machine is to imperative programming.</p>
<p><strong>The very basics</strong></p>
<p>Everything is a function in <img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus but for the purposes of this post we will extend the core calculus with integers and basic integer operations.  In a future post we will go into how integers can be represented as functions (for those unwilling to wait, check out Church Numerals).</p>
<p>Lets start with a sample expression:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+x%2By&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . x+y' title='&#92;lambda x . x+y' class='latex' /></p>
<p>This is called an <strong>abstraction</strong>.  In this expression we call the x variable <strong>bound</strong> and the y variable <strong>free</strong>.  There is one other operation called <strong>application</strong>.  Application takes the form of:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+x%2By+%5Bx+%3A%3D+3%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . x+y [x := 3]' title='&#92;lambda x . x+y [x := 3]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus evaluates expressions by simple substitution so the above expression simplifies to <img src='http://s0.wp.com/latex.php?latex=3%2By&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='3+y' title='3+y' class='latex' />.  One thing to note about this is that in the term <img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+M&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . M' title='&#92;lambda x . M' class='latex' /> where <img src='http://s0.wp.com/latex.php?latex=M&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='M' title='M' class='latex' /> is another term, only free occurences of <img src='http://s0.wp.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> get replaced.</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+%5Clambda+x+.+x%2Bz+%5Bx+%3A%3D+3%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . &#92;lambda x . x+z [x := 3]' title='&#92;lambda x . &#92;lambda x . x+z [x := 3]' class='latex' /> therefore simplifies to <img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+x%2Bz&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . x+z' title='&#92;lambda x . x+z' class='latex' />.</p>
<p><strong>All functions are functions of one variable</strong></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda' title='&#92;lambda' class='latex' />-Calculus does not allow abstractions that take multiple arguments.  Instead you write functions that return functions which take the next variable.</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+%5Clambda+y+.+x+%2B+y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . &#92;lambda y . x + y' title='&#92;lambda x . &#92;lambda y . x + y' class='latex' /></p>
<p>simplifying this with <img src='http://s0.wp.com/latex.php?latex=x+%3D+3%2C+y+%3D+4&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x = 3, y = 4' title='x = 3, y = 4' class='latex' /> we get:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+%5Clambda+y+.+x+%2B+y+%5Bx+%3A%3D+3%5D%5By+%3A%3D+4%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . &#92;lambda y . x + y [x := 3][y := 4]' title='&#92;lambda x . &#92;lambda y . x + y [x := 3][y := 4]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+y+.+3+%2B+y+%5By+%3A%3D+4%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda y . 3 + y [y := 4]' title='&#92;lambda y . 3 + y [y := 4]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=3+%2B+4&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='3 + 4' title='3 + 4' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=7&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='7' title='7' class='latex' /></p>
<p>For conciseness, <img src='http://s0.wp.com/latex.php?latex=%5Clambda+x+.+%5Clambda+y+.+M&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda x . &#92;lambda y . M' title='&#92;lambda x . &#92;lambda y . M' class='latex' /> can be written as <img src='http://s0.wp.com/latex.php?latex=%5Clambda+xy+.+M&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda xy . M' title='&#92;lambda xy . M' class='latex' /> but it is important to remember that this is a function that takes the value for x and returns a new function.</p>
<p><strong>The Y combinator</strong></p>
<p>It may have occured to you that recursion cannot be implemented with a simple substitution model and there are no looping constructs.  How can this be Turing Complete?  Recursion can be simulated by using a function <img src='http://s0.wp.com/latex.php?latex=Y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y' title='Y' class='latex' /> such that <img src='http://s0.wp.com/latex.php?latex=Yf+%5Cequiv+f+%28Yf%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Yf &#92;equiv f (Yf)' title='Yf &#92;equiv f (Yf)' class='latex' /> (ie. a fixed-point function), assume for the moment that such a function <img src='http://s0.wp.com/latex.php?latex=Y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y' title='Y' class='latex' /> exists.</p>
<p>If you wanted to represent the factorial function with recursion you could do it as:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Ctext%7BFactorial+%7Dx+%5Cequiv+%5Ctext%7B+if+%7D+x+%3D%3D+0+%5Ctext%7B+then+%7D+1+%5Ctext%7B+else+%7D+x+%2A+%5Ctext%7B+Factorial+%7D%28x-1%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{Factorial }x &#92;equiv &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * &#92;text{ Factorial }(x-1)' title='&#92;text{Factorial }x &#92;equiv &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * &#92;text{ Factorial }(x-1)' class='latex' /></p>
<p>Since terms are not named, and recursion is impossible, we have to write a function that takes (Yf) as a parameter.</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Clambda+f+.+%5Clambda+x+.+%5Ctext%7B+if+%7D+x+%3D%3D+0+%5Ctext%7B+then+%7D+1+%5Ctext%7B+else+%7D+x+%2A+f+%28x+-+1%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;lambda f . &#92;lambda x . &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * f (x - 1)' title='&#92;lambda f . &#92;lambda x . &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * f (x - 1)' class='latex' /></p>
<p>we&#8217;ll call this expression <img src='http://s0.wp.com/latex.php?latex=%5Ctext%7B+Fact+%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='&#92;text{ Fact }' title='&#92;text{ Fact }' class='latex' /> for brevity.</p>
<p>Since: <img src='http://s0.wp.com/latex.php?latex=Yf+%5Cequiv+f+%28Yf%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Yf &#92;equiv f (Yf)' title='Yf &#92;equiv f (Yf)' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+%5Ctext%7BFact%7D+%5Cequiv+%5Clambda+x+.+%5Ctext%7B+if+%7D+x+%3D%3D+0+%5Ctext%7B+then+%7D+1+%5Ctext%7B+else+%7D+x+%2A+f+%28x+-+1%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y &#92;text{Fact} &#92;equiv &#92;lambda x . &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * f (x - 1)' title='Y &#92;text{Fact} &#92;equiv &#92;lambda x . &#92;text{ if } x == 0 &#92;text{ then } 1 &#92;text{ else } x * f (x - 1)' class='latex' /> and f is bound to <img src='http://s0.wp.com/latex.php?latex=Y+%5Ctext%7BFact%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y &#92;text{Fact}' title='Y &#92;text{Fact}' class='latex' /> giving us recursion!</p>
<p>Now to show the (not-so-magical) fixed point function <img src='http://s0.wp.com/latex.php?latex=Y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y' title='Y' class='latex' />:</p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+%5Cequiv+%5Clambda+f+.+%28%5Clambda+x+.+f+%28xx%29%29%28%5Clambda+x+.+f%28xx%29%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y &#92;equiv &#92;lambda f . (&#92;lambda x . f (xx))(&#92;lambda x . f(xx))' title='Y &#92;equiv &#92;lambda f . (&#92;lambda x . f (xx))(&#92;lambda x . f(xx))' class='latex' /></p>
<p><strong>Proof</strong></p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+g+%3D+%28%5Clambda+f+.+%28%5Clambda+x+.+f+%28xx%29%29+%28%5Clambda+x+.+f%28xx%29%29%29+g&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y g = (&#92;lambda f . (&#92;lambda x . f (xx)) (&#92;lambda x . f(xx))) g' title='Y g = (&#92;lambda f . (&#92;lambda x . f (xx)) (&#92;lambda x . f(xx))) g' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+g+%3D+%28%5Clambda+x+.+g+%28xx%29%29+%28%5Clambda+x+.+g%28xx%29%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y g = (&#92;lambda x . g (xx)) (&#92;lambda x . g(xx))' title='Y g = (&#92;lambda x . g (xx)) (&#92;lambda x . g(xx))' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+g+%3D+g+%5B+%28+%5Clambda+x+.+g%28xx%29%29+%28+%5Clambda+x+.+g%28xx%29%29%5D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y g = g [ ( &#92;lambda x . g(xx)) ( &#92;lambda x . g(xx))]' title='Y g = g [ ( &#92;lambda x . g(xx)) ( &#92;lambda x . g(xx))]' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=Y+g+%3D+g+%28Y+g%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Y g = g (Y g)' title='Y g = g (Y g)' class='latex' /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=7&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2008/10/17/quick-and-dirty-intro-to-lambda-calculus-post-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>Taint mode doesn&#8217;t catch SQL injection bugs by default</title>
		<link>http://bniemczyk.wordpress.com/2007/03/01/taint-mode-doesnt-catch-sql-injection-bugs-by-default/</link>
		<comments>http://bniemczyk.wordpress.com/2007/03/01/taint-mode-doesnt-catch-sql-injection-bugs-by-default/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 16:38:00 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/2007/03/01/taint-mode-doesnt-catch-sql-injection-bugs-by-default/</guid>
		<description><![CDATA[After a friend pointed out an SQL injection bug in some of my Perl code, I was confused as to why taint mode had not caught it (I use -T for everything and recommend you do too). After checking the docs again, DBI only checks if statements are tainted if you set the TaintIn property [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=4&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a friend pointed out an <a href="http://en.wikipedia.org/wiki/SQL_injection" title="wikipedia">SQL injection</a> bug in some of my Perl code, I was confused as to why <a href="http://gunther.web66.com/FAQS/taintmode.html" title="Taint Mode FAQ">taint mode</a> had not caught it (I use -T for everything and recommend you do too).  After checking the docs again, DBI only checks if statements are tainted if you set the TaintIn property of the handle.  I&#8217;m not sure how I missed this before.  Personally, I think this is a brain-dead behaviour.  If a programmer is security conscious enough to enable taint mode, he probably wants to know about SQL injection bugs.</p>
<p>Update:<br />After enabling TaintIn for some of my code, DBI became even more retarded.  With TaintIn DBI also checks if your sql parameters are tainted.  So some code like<span style="font-style:italic;"> $sth = $dbh-&gt;prepare(&#8220;insert into mytable values (?)&#8221;); $sth-&gt;execute($user_supplied_data);</span> fails.  In my opinion this defeats the entire purpose of DBI parameters.  I may patch DBI locally and see if I can get it applied upstream.</p>
<p></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bniemczyk.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bniemczyk.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=4&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2007/03/01/taint-mode-doesnt-catch-sql-injection-bugs-by-default/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl Grep Replacement</title>
		<link>http://bniemczyk.wordpress.com/2007/02/16/perl-grep-replacement/</link>
		<comments>http://bniemczyk.wordpress.com/2007/02/16/perl-grep-replacement/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 19:59:00 +0000</pubDate>
		<dc:creator>bniemczyk</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://bniemczyk.wordpress.com/2007/02/16/perl-grep-replacement/</guid>
		<description><![CDATA[The script is a perl replacement for grep. It has a couple extra features that I like, and of course the best benefit is it uses perl regular expressions instead of posix.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=3&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a title="Perl Script" href="http://72.158.105.9/~brandon/scripts/mygrep.txt" target="_blank">script</a> is a perl replacement for grep.  It has a couple extra features that I like, and of course the best<br />
benefit is it uses perl regular expressions instead of posix.</p>
<hr />
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bniemczyk.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bniemczyk.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bniemczyk.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bniemczyk.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bniemczyk.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bniemczyk.wordpress.com&amp;blog=3904923&amp;post=3&amp;subd=bniemczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bniemczyk.wordpress.com/2007/02/16/perl-grep-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ee374f092f910633df0f94dd64476597?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bniemczyk</media:title>
		</media:content>
	</item>
	</channel>
</rss>
