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.

e fundamental issue with using locally named binders is the problem of name capture, or how to handle<br />

the case where a substitution conflicts with the names of free variables. We need the condition in the<br />

last case to avoid the naive substitution that would fundamentally alter the meaning of the following<br />

expression when y is rewritten to x.<br />

[y/x](λx.xy) → λx.xx<br />

By convention we will always use a capture-avoiding substitution. Substitution will only proceed if the<br />

variable is not in the set of free variables of the expression, and if it does then a fresh variable will be<br />

created in its place.<br />

(λx.e)a → [x/a]e<br />

if x /∈ fv(a)<br />

ere are several binding libraries and alternative implementations of the lambda calculus syntax that<br />

avoid these problems. It is a very common problem and it is very easy to implement incorrectly even for<br />

experts.<br />

Conversion and Equivalences<br />

Alpha equivalence<br />

(λx.e) α = (λy.[x/y]e)<br />

Alpha equivalence is the property ( when using named binders ) that changing the variable on the binder<br />

and throughout the body of the expression should not change the fundamental meaning of the whole<br />

expression. So for example the following are alpha-equivalent.<br />

λxy.xy<br />

α<br />

= λab.ab<br />

Beta-reduction<br />

Beta reduction is simply a single substitution step, replacing a variable bound by a lambda expression<br />

with the argument to the lambda throughout the body of the expression.<br />

Eta-reduction<br />

(λx.a)y β → [x/y]a<br />

λx.ex η → e if x /∈ fv(e)<br />

is is justified by the fact that if we apply both sides to a term, one step of beta reduction turns the left<br />

side to the right side:<br />

48

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

Saved successfully!

Ooh no, something went wrong!