25.10.2015 Views

Write You a Haskell Stephen Diehl

1kEcQTb

1kEcQTb

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In all the languages which we will implement the types present during compilation are erased. Although<br />

types are possibly present in the evaluation semantics, the runtime cannot dispatch on types of values at<br />

runtime. Types by definition only exist at compile-time in the static semantics of the language.<br />

Small-Step Semantics<br />

e real quantity we’re interested in formally describing is expressions in programming languages. A<br />

programming language semantics is described by the operational semantics of the language. e operational<br />

semantics can be thought of as a description of an abstract machine which operates over the<br />

abstract terms of the programming language in the same way that a virtual machine might operate over<br />

instructions.<br />

We use a framework called small-step semantics where a derivation shows how individual rewrites compose<br />

to produce a term, which we can evaluate to a value through a sequence of state changes. is is a<br />

framework for modeling aspects of the runtime behavior of the program before running it by describing<br />

the space of possible transitions type and terms may take. Ultimately we’d like the term to transition<br />

and terminate to a value in our language instead of becoming “stuck” as we encountered before.<br />

Recall our little calculator language from before when we constructed our first parser:<br />

data Expr<br />

= Tr<br />

| Fl<br />

| IsZero Expr<br />

| Succ Expr<br />

| Pred Expr<br />

| If Expr Expr Expr<br />

| Zero<br />

e expression syntax is as follows:<br />

e ::= True<br />

False<br />

iszero e<br />

succ e<br />

pred e<br />

if e then e else e<br />

0<br />

e small step evaluation semantics for this little language is uniquely defined by the following 9 rules.<br />

ey describe each step that an expression may take during evaluation which may or may not terminate<br />

and converge on a value.<br />

57

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

Saved successfully!

Ooh no, something went wrong!