25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

λx.e<br />

ere are several syntactical conventions that we will adopt when writing lambda expressions. Application<br />

of multiple expressions associates to the left.<br />

x 1 x 2 x 3 ...x n = (...((x 1 x 2 )x 3 )...x n )<br />

By convention application extends as far to the right as is syntactically meaningful. Parenthesis are used<br />

to disambiguate.<br />

In the lambda calculus all lambda abstractions bind a single variable, their body may be another lambda<br />

abstraction. Out of convenience we often write multiple lambda abstractions with their variables on one<br />

lambda symbol. is is merely a syntactical convention and does not change the underlying meaning.<br />

λxy.z = λx.λy.z<br />

e actual implementation of the lambda calculus admits several degrees of freedom in how they are<br />

represented. e most notable is the choice of identifier for the binding variables. A variable is said to<br />

be bound if it is contained in a lambda expression of the same variable binding. Conversely a variable is<br />

free if it is not bound.<br />

A term with free variables is said to be an open term while one without free variables is said to be closed<br />

or a combinator.<br />

e 0 = λx.x<br />

e 1 = λx.(x(λy.ya)x)y<br />

e 0 is a combinator while e 1 is not. In e 1 both occurances of x are bound. e first y is bound, while the<br />

second is free. a is also free.<br />

Multiple lambda abstractions may bind the same variable name. Each occurance of a variable is then<br />

bound by the nearest enclosing binder. For example the x variable in the following expression is bound<br />

on the inner lambda, while y is bound on the outer lambda. is phenomenon is referred to as name<br />

shadowing.<br />

λxy.(λxz.x + y)<br />

SKI Combinators<br />

ere are three fundamental closed expressions called the SKI combinators.<br />

S = λf.(λg.(λx.fx(gx)))<br />

K = λx.λy.x<br />

I = λx.x<br />

45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!