<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Burge School of Functional Programming</title>
    <link href="http://jmct.cc/burge.xml" rel="self" />
    <link href="http://jmct.cc" />
    <id>http://jmct.cc/burge.xml</id>
    <author>
        <name>JMCT</name>
        <email>jmct@jmct.cc</email>
    </author>
    <updated>2017-01-09T00:00:00Z</updated>
    <entry>
    <title>1: Expressions</title>
    <link href="http://jmct.cc/1/index.html" />
    <id>http://jmct.cc/1/index.html</id>
    <published>2017-01-09T00:00:00Z</published>
    <updated>2017-01-09T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h1>1: Expressions</h1>
<h3>Jan  9, 2017</h3>
<h1 id="preface">Preface</h1>
<p>Welcome to part 2 of <a href="http://jmct.cc/burge.html">“The Burge School of Functional Programming”</a>. <a href="http://jmct.cc/intro/index.html">Last time</a> I claimed that Burge’s 1975 book “Recursive Programming Techniques” is a gem of Functional Programming that deserves to be more widely known. Burge’s book gets to the core of what Functional Programming is about, and it’s not fancy type systems or mathematical jargon; it’s <em>expressions</em>. This post is where we really pinpoint what an expression is. If I’m going to convince you that functional programing is about expressions, we should be really clear what we mean by that!</p>
<p>In later posts we’ll look at how to build up an entire programming language from what’s described here, and how that reflects one of the great ideas in Functional Programming: constructing software systems from <em>small</em> expressions that can be understood <em>in isolation</em>.</p>
<p>Throughout this series, I will use the notation that Burge used. However, I aim to point out when those notations differ from modern conventions.</p>
<p>I’m going to quote directly from the book a lot early on in this post, as I feel there’s a lot of insight to be found at the beginning of Burge’s first chapter.</p>
<h1 id="introduction">Introduction</h1>
<p>Burge hits the ground running with the introductory chapter of the book, making it clear that the style of programming this book advocates is a bit different from what the reader may be used to. On the very first page he states:</p>
<blockquote>
<p>All the linguistic devices introduced [in this book] are based upon two methods of constructing expressions from smaller expressions […] Thus the extra notation that is added to this basis adds no new structural features</p>
</blockquote>
<p>He names the extra notation <em>additions</em>. These days we would call it <em>syntactic sugar</em>, but the idea is identical: New forms of expression that can be translated to a few core constructs. Let that sink in: all of the language constructs that Burge describes in his book can be rewritten with just the two following constructs:</p>
<ol type="1">
<li>“An operator/operand construction that denotes function application”</li>
<li>“An expression format which denotes a function”</li>
</ol>
<p>Burge does remind the reader that there will be some ‘constants’ (we’d call them <em>primitives</em>) required for certain tasks. This sets up one of the first great insights of the text, stating that the constructs</p>
<blockquote>
<p>create a practical and powerful programming system, which is more like a <em>family</em> of programming languages than a single language, because the features introduced are concerned more with combining functions to produce new ones than with the nature of the primitive functions that are being combined.</p>
</blockquote>
<p>Here comes the kicker:</p>
<blockquote>
<p>A programming language for a particular range of applications can be obtained by adding an appropriate set of primitives to this basic structure.</p>
</blockquote>
<p>These days we call a “language for a particular range of applications” a Domain Specific Language (DSL). DSLs are a very powerful tool in the functional programmer’s toolbox. So in just under a page Burge has set the stage for understanding functional programming through just a few core constructs and its usefulness in creating <a href="https://en.wikipedia.org/wiki/Domain-specific_language">DSLs</a> but avoids using any jargon. So Burge’s lesson so far: understand two core constructs, then pick primitives according to your domain.</p>
<p>We haven’t gotten much further in the decades since.</p>
<p>He’s not done yet, there’s one more insight waiting for us, right before he starts introducing the core constructs he reminds us that the focus is on <em>expressions</em> and not <em>mechanisms</em>. He argues that expressions have a great property:</p>
<blockquote>
<p>the value, or meaning, of an expression depends in a simple way only on the values of its subexpressions and on no other properties of them.</p>
</blockquote>
<p>So again, without leaning on fancy language, Burge lays it all out in front of us. He states that this property allows you solve large and complex problems by breaking them down into small, simple, and independent problems. And</p>
<blockquote>
<p>it is possible to make the structure of the program match the structure of the problem being solved.</p>
</blockquote>
<h1 id="the-language">The Language</h1>
<h2 id="operatoroperand-expressions">Operator/Operand Expressions</h2>
<p>Let’s start with the obvious: Functional Programming deals with functions. This makes it critical to specify what we mean when we say <em>function</em>. Burge does this by talking about the relationship a function has to its arguments. More specifically, he talks about types, starting with function types.</p>
<p>But remember, this is a book from decades ago, so we’re not bringing in any heavy machinery here. Note that Burge never talks about type-checking or even implementing a type system. Even if your compiler doesn’t do type checking, you can still benefit from thinking about types.</p>
<h3 id="functions-and-types">Functions and types</h3>
<p>I’ve been going on about <em>expressions</em> over <em>mechanisms</em> for a while and I haven’t even shown you an expression yet. So let’s take a look at one: <span class="math inline">\(f(x)\)</span>. This is how Burge typesets the application of the function <span class="math inline">\(f\)</span> to the value <span class="math inline">\(x\)</span>. This is the first expression we’ve seen, so let’s unpack it. <span class="math inline">\(f(x)\)</span> is a function application, which has two parts; an <em>operator</em> (in this case <span class="math inline">\(f\)</span>), and an <em>operand</em> (in this case <span class="math inline">\(x\)</span>). This makes function application a type of <em>compound</em> expression.</p>
<p>In the introduction I claimed that all of the language constructs we will introduce can be understood with just two concepts; function application is the first one! The basic idea of looking at application as a compound expression is that in order to make sense of the expression <span class="math inline">\(f(x)\)</span> you’re going to have to make sense of <span class="math inline">\(f\)</span> and of <span class="math inline">\(x\)</span>. That may seem obvious, but the insight Burge is trying to get across to you is that when you program in this expression-based style you make sense of each in isolation. That’s a very powerful idea!</p>
<p>Okay, so a function is a value that you can <em>apply</em> to other values (a.k.a. the inputs). However, not all values make sense as inputs; for example, the function <span class="math inline">\(square\)</span> that takes a number and multiplies it by itself, does not make much sense if you give it the letter ‘a’ as an input. Let’s be a bit more concrete and say functions have a <em>type</em>, usually written as</p>
<p><span class="math display">\[A \longrightarrow B\]</span></p>
<p>Here the <span class="math inline">\((\rightarrow)\)</span> is what indicates this is a function. The <span class="math inline">\(A\)</span> is the type of value it accepts, and <span class="math inline">\(B\)</span> is the type of values it returns. Burge calls these the <em>domain</em> and <em>range</em>, respectively.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a> So if you have a function <span class="math inline">\(f\)</span> of type <span class="math inline">\(A \rightarrow B\)</span>, and you apply it to a value <span class="math inline">\(x\)</span> which has type <span class="math inline">\(A\)</span>, the result is of type <span class="math inline">\(B\)</span>. Burge typesets function application as both <span class="math inline">\(f(x)\)</span> or <span class="math inline">\(f\ x\)</span>.</p>
<p>Earlier I mentioned the function <span class="math inline">\(square\)</span>. One possible type for <span class="math inline">\(square\)</span> would be<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
<p><span class="math display">\[square \in (\text{integer} \rightarrow \text{integer})\]</span></p>
<p>Other common examples:</p>
<p><span class="math display">\[ 
sin \in (\text{real} \rightarrow \text{real}) \\
log \in (\text{positive} \rightarrow \text{real}) \\
negate \in (\text{positive} \rightarrow \text{negative})
\]</span></p>
<p>So in general anything of the form <span class="math inline">\(g \in (A \rightarrow B)\)</span> is an assertion that <span class="math inline">\(g\)</span> is a function that takes arguments of type <span class="math inline">\(A\)</span> and returns values of type <span class="math inline">\(B\)</span>. This means if we have a value <span class="math inline">\(x\)</span> of type <span class="math inline">\(A\)</span>, we can be assured that <span class="math inline">\(g(x) \in B\)</span>.</p>
<p>Okay, this is all well and good, but every function we’ve looked at takes only a single argument, what about things like <span class="math inline">\(+\)</span>? Here are some examples:</p>
<p><span class="math display">\[
+ \in (\text{real} \times \text{real} \rightarrow \text{real})\\
min \in (\text{real} \times \text{real} \rightarrow \text{real})\\
equal \in (\text{real} \times \text{real} \rightarrow \text{truth value})
\]</span></p>
<p>This is just saying that these functions take two arguments, both reals, and return a single value. This generalizes in the obvious way to functions with an arbitrary number of arguments. So a function that takes <span class="math inline">\(N\)</span> arguments would have a type like</p>
<p><span class="math display">\[A_{1} \times A_{2} \times \dots \times A_{N} \rightarrow B\]</span></p>
<p>Where <span class="math inline">\(A_{i}\)</span> is the appropriate type of the <span class="math inline">\(i^{th}\)</span> argument. In other words, <span class="math inline">\(A \times B\)</span> defines the type of <em>pairs</em> where the first element is of type <span class="math inline">\(A\)</span> and the second element is of type <span class="math inline">\(B\)</span>.</p>
<p>Now, the traditional way to apply functions that take multiple arguments is by extending the syntax we already have, giving us <span class="math inline">\(min(x,y)\)</span> or <span class="math inline">\(+(x,y)\)</span>. Many languages have a predetermined set of special functions that can be applied differently, the arithmetic operations are usually such an exception, so you could write <span class="math inline">\(x + y\)</span> instead of <span class="math inline">\(+(x,y)\)</span>. Burge is no different here and his language allows for certain functions to be applied in this special manner.</p>
<p>It’s worth pointing out that even if you have a special syntax for the application of certain functions, <em>the operator/operand relationship is unchanged</em>. It could be argued that allowing any such special syntax obscures this relationship and therefore obscures the meaning of the expression<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a>. The important bit is that regardless of the syntax it is crucial that you be able to identify the operator and the operand of a function application.</p>
<h3 id="quick-aside-about-types">Quick aside about types</h3>
<p>This is pretty much the extent of what we’ll say about types, possibly for the whole series. Though types are used to describe things (as we’ll see in the next section), Burge never defines a type system, or any form of static enforcement of types. So why mention types at all? Because it’s important to <em>think</em> about types when you’re doing functional programming, particularly to distinguish between things that you can apply (functions), what they expect as argument values, etc.; and things you can’t apply (the number <span class="math inline">\(5\)</span>, for instance).</p>
<p>Many of the experts of dynamic languages I’ve interacted with will be the first to tell you: thinking about types is important when writing programs. But we don’t have to get fancy with our type system in order to have any benefit from the <em>concept</em> of types.</p>
<h3 id="meaning-of-expressions">Meaning of expressions</h3>
<p>We now know what makes up a function application (the operator and operand), but we still don’t know the <em>meaning</em> of anything. I claimed earlier that you can determine the meaning of a function application by finding the meaning of its operator and operand. But eventually you’ll reach an expression that is not a function application, Burge calls these <em>simple</em> expressions. In this section we will explain the meaning of one type of simple expression: <em>constants</em> (variables are the other type of simple expression, which we’ll get to a bit later).</p>
<p>In any programming system there is a set of constants (what we would call primitives). The meaning of these constants is given by the system and its implementation. The most obvious constants are things like numbers: <span class="math inline">\(4\)</span>, <span class="math inline">\(-128\)</span>, etc.<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a> or arithmetic operations: <span class="math inline">\(+\)</span>, <span class="math inline">\(-\)</span>, <span class="math inline">\(\times\)</span>, etc.</p>
<p>So if your language has the constant <span class="math inline">\(+\)</span> which takes two numbers and adds them together, and it has numeric constants we can now find the meaning of expressions like <span class="math inline">\(+(4,5)\)</span>, or <span class="math inline">\(square(\times(2,3))\)</span>.</p>
<p>We do this with the following procedure:</p>
<ol type="1">
<li>If the expression is simple, what is the meaning of the constant?</li>
<li>If the expression is composite, what is the meaning of its operator, and what is the meaning of its operand?</li>
</ol>
<p>Try applying this series of steps to <span class="math inline">\(+(4,5)\)</span>, or <span class="math inline">\(square(\times(2,3))\)</span>. Do yourself a favor and force yourself to actually go through the steps. In this instance it is not very hard, but it is the practice of finding the meaning of expressions via the meaning of their constituent parts that is important.</p>
<p>For the rest of the post we’ll allow ourselves to use the arithmetic operators as <a href="https://en.wikipedia.org/wiki/Infix_notation">infix</a>, i.e. <span class="math inline">\(4 + 5\)</span>.</p>
<h3 id="what-it-means-to-be-first-class-or-functions-are-values-too">What it means to be first-class; or, functions are values too!</h3>
<p>Burge uses two conventions when writing function application. The first is what we’ve seen up to this point: <span class="math inline">\(f(x)\)</span> or <span class="math inline">\(f(x,y)\)</span>. This is very common and is likely to be what most languages you’re familiar with use. The second convention Burge uses is more unusual: <span class="math inline">\(f\ x\)</span> or <span class="math inline">\(f\ x\ y\)</span>, respectively. Burge explains that these aren’t really different syntaxes for function application, but really represent functions of different types!</p>
<p>It’s clearer with two argument functions. Take the functions <span class="math inline">\(addT\)</span> and <span class="math inline">\(addC\)</span><a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a>, both of which add two numbers together. These are their types:</p>
<p><span class="math display">\[
addT \in (\text{real} \times \text{real} \rightarrow \text{real})\\
addC \in (\text{real} \rightarrow (\text{real} \rightarrow \text{real}))
\]</span></p>
<p>The types tell us that <span class="math inline">\(addT\)</span> takes a <em>pair</em> of real numbers and returns a real number, while <span class="math inline">\(addC\)</span> takes a <em>single</em> real number and returns a <em>function</em> of type <span class="math inline">\((\text{real} \rightarrow \text{real})\)</span>. Therefore, when we write <span class="math inline">\(addC\ x\
y\)</span>, we’re really writing <span class="math inline">\((addC\ x)\ y\)</span>, i.e. we’re applying the function <span class="math inline">\((addC\ x)\)</span> to <span class="math inline">\(y\)</span>. We can omit the brackets because function application <a href="https://en.wikipedia.org/wiki/Associative_property">associates</a> to the left. Similarly the function type <span class="math inline">\((\rightarrow)\)</span> associates to the right, so <span class="math inline">\((A \rightarrow (B \rightarrow C))\)</span> is the same as <span class="math inline">\((A \rightarrow B \rightarrow C)\)</span>.</p>
<p>To really hit the lesson home, convince yourself that the following are all equivalent for a function, <span class="math inline">\(f\)</span>, that takes three arguments</p>
<p><span class="math display">\[
((f\ x)\ y) \ z\\
(f\ x\ y) \ z\\
f\ x\ y \ (z)
\]</span></p>
<p>and understand why <span class="math inline">\(f\ x\ (y\ z)\)</span> is not equivalent to the three above<a href="#fn6" class="footnote-ref" id="fnref6"><sup>6</sup></a>. Here’s a hint: think of what the operator/operand relationships are for every function application, even the symbols within brackets.</p>
<p>For extra credit, draw a tree of the operator/operand (function/argument) parts for each version, including <span class="math inline">\(f\ x\ (y\ z)\)</span>.</p>
<p>This is not just some clever rationalization of multi-argument functions, this is a direct consequence of functions themselves being values. Because they are values just like anything else we can also <em>pass</em> functions to other functions, take the following example:</p>
<p><span class="math display">\[
twice\ f\ x = f\ (f\ x)
\]</span></p>
<p><span class="math inline">\(twice\)</span> is a function that takes two arguments, a function and some other value, and then applies the function ‘twice’ to the value. So if we had a function <span class="math inline">\(add\text{-}one\)</span> which adds 1 to a number and called <span class="math inline">\(twice\
add\text{-}one\ 5\)</span> we would get 7.</p>
<p>Treating functions as ‘first-class’ values has become quite ubiquitous these days, and for good reason! First-class functions allow you separate the <em>form</em> of a computation from the task being accomplished. This is one of the more powerful ideas from functional programming, and as such, Burge will explore it in depth later on.</p>
<h2 id="variables-and-lambdas">Variables and Lambdas</h2>
<p>Up to now we’ve used variables without discussing them, because many of us will have an intuition for what variables mean from other languages or from algebra in school. In this section we’ll be more precise about what a variable means.</p>
<p>Take the following mathematical equation:</p>
<p><span class="math display">\[
f\ x = (5 \times x) + 2
\]</span></p>
<p>This is a function over the variable <span class="math inline">\(x\)</span>. When you plug in different values for <span class="math inline">\(x\)</span> you get different results.</p>
<p>There are two very important properties about variables like the ones in the equation above. The first is that it doesn’t matter what name we give <span class="math inline">\(x\)</span>: <span class="math inline">\(f\
y = 5y +2\)</span> is the <em>exact</em> same equation with the exact same meaning. The second is that in mathematics we don’t actually <em>change</em> the values of a variable: Once we’ve plugged in a value for <span class="math inline">\(x\)</span> that value remains the same.</p>
<p>To better formalise how variables work we’ll use a notation developed by <a href="https://en.wikipedia.org/wiki/Alonzo_Church">Alonzo Church</a>. The following defines the same function using <em>lambda (<span class="math inline">\(\lambda\)</span>) notation</em>:</p>
<p><span class="math display">\[
\lambda x.(5 \times x) + 2
\]</span></p>
<p>We haven’t given the lambda expression a name, which is why in some languages they call lambdas ‘anonymous functions’. There’s nothing stopping us from giving the above a name though</p>
<p><span class="math display">\[
f = \lambda x.(5 \times x) + 2
\]</span></p>
<p>defines the same function again, this time giving it the name <span class="math inline">\(f\)</span>. Here is the crucial point: <span class="math inline">\(f\ x = (5 \times x) + 2\)</span> and <span class="math inline">\(f = \lambda x.(5 \times x) + 2\)</span> are <em>the same function</em>.</p>
<h3 id="taking-lambdas-apart">Taking lambdas apart</h3>
<p>In the same way that function application had two parts, the operator and the operand, lambda expressions also have two parts: the <em>bound variable</em> and the <em>body</em>. Everything between the lambda (<span class="math inline">\(\lambda\)</span>) and the period (<span class="math inline">\(.\)</span>) is the bound variable and everything after the period is the body.</p>
<p>Lambda expressions are functions, which means you can apply values to them (i.e they can be the operator part of a function application). When you apply a value to a lambda expression you substitute that value wherever the bound variable appears in the body and get rid of the bound variable part of the lambda expression, leaving only the body. So <span class="math inline">\((\lambda x. x + x)\ 5\)</span> becomes <span class="math inline">\(5 + 5\)</span>.</p>
<p>We can happily pass lambda expressions to other functions as well (since they are values themselves). Remembering the definition of <span class="math inline">\(twice\)</span> from earlier, the expression</p>
<p><span class="math display">\[
twice\ (\lambda x. x + 1)\ 5
\]</span></p>
<p>is equal to <span class="math inline">\(7\)</span>.</p>
<p>What about multi-argument functions? Well we already learned that multi-argument functions are just single argument functions that return functions, so let’s apply that idea here and define <span class="math inline">\(add\)</span> with lambdas:</p>
<p><span class="math display">\[
add = \lambda x.\lambda y. x + y
\]</span></p>
<p>This actually makes what’s happening when we <em>partially apply</em> a function more clear. If we only pass <span class="math inline">\(add\)</span> one argument what do we get? <span class="math inline">\((\lambda x.\lambda y. x + y)\ 1\)</span> becomes <span class="math inline">\(\lambda y. 1 + y\)</span>, or the function that adds <span class="math inline">\(1\)</span> to its argument.</p>
<h2 id="expressions">Expressions</h2>
<p>So we’ve spent a lot of time going on about function application, lambda expressions, and simple expressions (constants and variables). What do we know now? Well we know all the forms an expression can take. To paraphrase Burge:</p>
<blockquote>
<p>An expression is</p>
<ul>
<li>either simple and is a identifier</li>
<li>or a <em>lambda expression</em> + and has a <em>bound variable</em> which is an identifier + and a <em>body</em> which is an expression</li>
<li>or it is a <em>function application</em> + and has an <em>operator</em> and an <em>operand</em>, both of which are expressions</li>
</ul>
</blockquote>
<p>In the next post we’ll show you the language Burge describes in full, but it’s important to emphasize: Every language construct we will show you can be translated to expressions consisting only of what’s described above. A whole <em>family of languages</em> arises from the three possibilities above. As promised, we have two ways of combining expressions: lambda expressions and function application. The only other piece is that we need a way to refer to things, which is where the identifiers (variables or constants) come in..</p>
<h1 id="conclusion">Conclusion</h1>
<p>The core of Burge’s book, and Functional Programming more generally, is in what is possible with expressions. From this fact stems a lot of what makes Functional Programming such an interesting and exciting field. It affects the way we think about data, the way we think about program structure, and even how we <em>implement</em> our languages. Once equipped with these tools it’s easy to see the shared principles of all functional languages.</p>
<p>It’s very easy to get intimidated by a lot of the language that is thrown around in certain Functional Programming circles these days, but rest assured; understanding expressions and how we can reason about them and manipulate them gets you much further than diving into arcane mathematics ever will.</p>
<p>The rest of the series is going to be a pretty crazy ride, and it all comes back to what we’ve learned here; that expressions come in three mains forms: identifiers, function applications, and lambdas.</p>
<p>Buckle up.</p>
<h1 id="epilogue">Epilogue</h1>
<p><a href="https://twitter.com/josh_triplett">Josh Triplett</a>, <a href="https://twitter.com/kelleyrobinson">Kelley Robinson</a>, <a href="https://twitter.com/heathercmiller">Heather Miller</a>, <a href="https://twitter.com/rob_rix">Rob Rix</a>, and <a href="https://twitter.com/MichaelJBanks">Michael Banks</a> all gave constructive feedback on drafts of this post. Thank them if any of this made sense.</p>
<p>And of course, as promised, we’ve got another Prog Rock hit from the early 70’s, this one’s about a show “you’ve got to see”, a.k.a. how all of the language constructs we are used to can be made up of just expressions ;)</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/IwSTe9uit48" frameborder="0" allowfullscreen>
</iframe>
<p>-JMCT</p>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Note that in modern programming language texts and papers <em>range</em> would almost universally be called the <em>codomain</em>. The reasoning is simple: The range of a function is the set of values it <em>actually</em> returns, whereas the codomain is the set of <em>possible</em> return values. So when reasoning about types we’re actually reasoning about the codomain.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>Here the symbol <span class="math inline">\(\in\)</span> can be pronounced as ‘has the type’. The use of this symbol, which is borrowing from <a href="https://en.wikipedia.org/wiki/Set_theory">Set Theory</a>, has fallen out of favor since the 80’s. The reason for this is that types aren’t <em>really</em> sets, and so using that notation implied something that wasn’t always true. These days you’ll almost universally see the symbol ‘<span class="math inline">\(:\)</span>’ used (e.g. <span class="math inline">\(\ f : A \rightarrow B\)</span>), unless you’re reading something written with Haskell in mind, where it would be <span class="math inline">\(f :: A \rightarrow B\)</span>.<a href="#fnref2" class="footnote-back">↩</a></p></li>
<li id="fn3"><p>The LISP, Racket, and Clojure communities might make this argument, for example.<a href="#fnref3" class="footnote-back">↩</a></p></li>
<li id="fn4"><p>The constants are defined by the system in use and aren’t necessarily equivalent to their pure mathematical counterparts. For example adding two numbers in many languages introduces the possibility of overflow, whereas the ‘true’ <span class="math inline">\(+\)</span> has no such possibility. Or how some languages automatically convert all numeric values to floating point, etc.<a href="#fnref4" class="footnote-back">↩</a></p></li>
<li id="fn5"><p>For those that are curious about the naming, <span class="math inline">\(addT\)</span> is the adding a tuple, and <span class="math inline">\(addC\)</span> is the ‘<a href="https://en.wikipedia.org/wiki/Currying">curried</a>’ addition.<a href="#fnref5" class="footnote-back">↩</a></p></li>
<li id="fn6"><p>The difference is that in <span class="math inline">\(f\ x\ (y\ z)\)</span> only <em>two</em> arguments have been passed to <span class="math inline">\(f\)</span>: <span class="math inline">\(x\)</span> and <span class="math inline">\((y\ z)\)</span>. The expression <span class="math inline">\((y\ z)\)</span> is itself a function application with <span class="math inline">\(y\)</span> as the operator and <span class="math inline">\(z\)</span> as the operand.<a href="#fnref6" class="footnote-back">↩</a></p></li>
</ol>
</section>
<!--<p class="twitter_follow">If you like this post, you should follow me on
  <a href="http://twitter.com/josecalderon">twitter.</a>
</p>-->
]]></summary>
</entry>
<entry>
    <title>Introduction</title>
    <link href="http://jmct.cc/intro/index.html" />
    <id>http://jmct.cc/intro/index.html</id>
    <published>2016-12-23T00:00:00Z</published>
    <updated>2016-12-23T00:00:00Z</updated>
    <summary type="html"><![CDATA[<h1>Introduction</h1>
<h3>Dec 23, 2016</h3>
<h1 id="preface">Preface</h1>
<p>This is the first in a <a href="http://jmct.cc/burge.html">series of posts</a> about what I am calling the “Burge School of Functional Programming”. When I originally <a href="https://twitter.com/josecalderon/status/804154036375187458">tweeted</a> that I was going to do this, I called it the “Burge-Runciman” School, but upon further reflection I think that they are distinct and I was being clouded by the fact that it was <a href="https://www-users.cs.york.ac.uk/colin/">Colin Runciman</a> who taught me about Burge.</p>
<h2 id="motivation">Motivation</h2>
<p>There has been a lot of discussion online in the past few years about what Functional Programming <em>is</em>. This discussion comes in waves and we recently had a high-point when a list claiming to classify levels of Functional Programming was widely distributed.</p>
<p>I, as well as many of my colleagues, found the list a bit disconcerting. It is a dangerous game to try and make such a prescriptive list about a topic; it is a near certainty that any benefits of such a list are far outweighed by the likelihood of any such list alienating those who are looking to get started in Functional Programming.</p>
<p>Independent of the situation I just described, I’ve been dissatisfied with the attitude that Haskell is the ‘truest’ Functional Language, or that it somehow exhibits FP in its ‘purest’ form. Because of this I have wanted to write about some Functional Programming history for a few years now. In particular I want to draw some attention to William H. Burge’s book “Recursive Programming Techniques”, which is a (sometimes forgotten) gem of Functional Programming.</p>
<h2 id="background">Background</h2>
<p>When I was a PhD student at York, I remember reading a paper about parser combinators in Haskell. I went into Colin Runciman’s office and expressed my joy, and in particular I expressed something like “it’s amazing that they were able to come up with something like that!”. This was early days of my PhD when I still wasn’t so great at identifying what’s <em>actually</em> novel in a paper. Colin told me to wait a minute and he went to his bookshelf and grabbed an old book: “Recursive Programming Techniques” by William H. Burge. He suggested I read it.</p>
<p>The book was first published in 1975, three years before Backus’ famous Turing award lecture <a href="http://dl.acm.org/citation.cfm?id=359579">“Can programming be liberated from the von Neumann style?”</a>, which is often seen as a watershed moment in the history of functional programming because it brought so much attention to the field. In my view Burge’s book has aged much better than Backus’ lecture, but that is likely due to other factors.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
<h1 id="the-burge-school">The Burge School</h1>
<p>Burge’s book is, in my opinion, one of the best publications on what functional programming is about. This is made even more intriguing when you think about what <em>wasn’t</em> around when this book was first published. In 1975 we did <em>not</em> have:</p>
<ul>
<li>Polymorphic Type Inference</li>
<li>Algebraic Data types</li>
<li>Lazy languages<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></li>
<li>Lots of Category-theoretic terminology as part of functional programming</li>
</ul>
<p>This is in contrast to how many commentators online talk about functional programming. However, much in the same way that music is not a set of instruments, functional programming is not a set of abstractions that we need to learn and memorize. Functional programming is an <em>approach</em> to solving computational problems.</p>
<p>Many of the abstractions that you do read about are ways to apply this approach to new problems, or problems that were difficult to solve without reaching for more traditional programming methods. But the essence, the core, of what functional programming is about is mostly unchanged.</p>
<p>In the preface to the book Burge writes (emphasis mine):</p>
<blockquote>
<p>The main emphasis [of this book] is placed on those parts of the language, namely expressions, that denote the end results sought from the computer, rather than on the instructions which the machine must follow in order to achieve the results. <em>The main thesis of this book is that, in many cases, this emphasis on expressions as opposed to mechanisms simplifies and improves the task of programming.</em></p>
</blockquote>
<p>The above will be familiar to anyone who has had the good fortune of taking a well designed functional programming course. This is the paradigm shift that sometimes makes functional programming hard to learn for those that are used to other methods of programming. Expressions over mechanisms.</p>
<h2 id="the-book">The Book</h2>
<p>Part of what makes this book so interesting is that it was published as part of a series on programming from IBM. The series was called “The Systems Programming Series” and its charter was</p>
<blockquote>
<p>a long term project to collect, organize, and publish those principles and techniques that would have lasting value throughout the industry.</p>
</blockquote>
<p>IBM was trying to combat the tendency for systems programmers to all continually reinvent the wheel. In other words, this was not a series for the navel gazers in the Ivory Tower, this was for those on the ground programming real systems and solving ‘real world’ problems. Granted, the programming tasks of the day weren’t necessarily the same tasks that a programmer today might be focusing on, but the tools and techniques are more similar than one might think.</p>
<p>The book itself is divided into 5 chapters:</p>
<ol type="1">
<li>Basic Notions and Notations</li>
<li>Program Structure</li>
<li>Data Structures</li>
<li>Parsing</li>
<li>Sorting</li>
</ol>
<p>In the coming weeks we will take a look at each chapter and highlight Burge’s insights. The goal here is to provide a counter to the checklist approach to functional programming material. The core ideas are all here, my hope is that once those are internalized a lot of the modern discourse on Functional Programming can be seen in a new light.</p>
<h2 id="epilogue">Epilogue</h2>
<p>Many of the older functional programmers I know were big Prog Rock fans. I find it fitting that many of those that were early proponents of what was a radical programming methodology were into radical music as well. I don’t know Burge, but I like to imagine that the soundtrack of the 1970’s was in the air as he was writing this book. With that spirit I’m going to link to a Prog Rock hit from the early to mid 1970’s with each post; because, why not?</p>
<p>So, for all of those early functional programmers that were called ‘dreamers’:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/xkkvBfWAXgI" frameborder="0" allowfullscreen>
</iframe>
<p>-JMCT</p>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>Backus was trying to do more than just explain functional programming in his lecture, he was trying to turn the tide of programming language research. Because of this some of the technical work in the lecture has not aged super well. For instance in certain parts of the paper Backus emphasises point-free programming using an APL-style syntax. In the decades since the general consensus has moved away from this style.<a href="#fnref1" class="footnote-back">↩</a></p></li>
<li id="fn2"><p>There were call by name languages, and the concept of a delayed computation or a ‘thunk’ was already well known. But I’d argue that the study of laziness <em>as a discipline</em> really only took off in the later 1970’s with the famous papers <a href="http://dl.acm.org/citation.cfm?id=811543">“A Lazy Evaluator”</a> (1976) and <a href="http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR44">“CONS should not Evaluate its Arguments”</a> (also 1976). Let me know if I’ve missed something there.<a href="#fnref2" class="footnote-back">↩</a></p></li>
</ol>
</section>
<!--<p class="twitter_follow">If you like this post, you should follow me on
  <a href="http://twitter.com/josecalderon">twitter.</a>
</p>-->
]]></summary>
</entry>

</feed>
