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.

Well-typed programs cannot “go wrong”.<br />

— Robin Milner<br />

Evaluation<br />

While the lambda calculus is exceedingly simple, there is a great deal of variety in ways to evaluate<br />

and implement the reduction of lambda expressions. e different models for evaluation are evaluation<br />

stratgies.<br />

ere is a bifurcation between two points in the design space: strict and non-strict evaluation. An evaluation<br />

strategy is strict if the arguments to a lambda expression are necessarily evaluated before a lambda<br />

is reduced. A language in which the arguments are not necessarily evaluated before a lambda is reduced<br />

is non-strict.<br />

Alternatively expressed, diverging terms are represented up to equivalence by the bottom value, written<br />

as ⊥. A function f is non-strict if:<br />

f⊥ ≠ ⊥<br />

Evaluation Models<br />

ere are many different models, and various hybrids thereof. We will consider three dominant models:<br />

• Call-by-value: arguments are evaluated before a function is entered<br />

• Call-by-name: arguments are passed unevaluated<br />

• Call-by-need: arguments are passed unevaluated but an expression is only evaluated once and<br />

shared upon subsequent references<br />

Given an expression fx the reduction in different evaluation models proceeds differently:<br />

Call-by-value:<br />

1. Evaluate x to v<br />

2. Evaluate f to λy.e<br />

3. Evaluate [y/v]e<br />

Call-by-name:<br />

68

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

Saved successfully!

Ooh no, something went wrong!