Skip to content

Commit 59bef9e

Browse files
committed
changes to the Evaluation chapter
1 parent c58a503 commit 59bef9e

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

005_evaluation.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ There are many different models, and various hybrids thereof. We will consider t
3636
dominant models:
3737

3838
* Call-by-value: arguments are evaluated before a function is entered
39-
* Call-by-name: arguments passed unevaluated
40-
* Call-by-need: arguments passed unevaluated but an expression is only evaluated
39+
* Call-by-name: arguments are passed unevaluated
40+
* Call-by-need: arguments are passed unevaluated but an expression is only evaluated
4141
once and shared upon subsequent references
4242

4343
Given an expression $f x$ the reduction in different evaluation models proceeds
@@ -81,9 +81,10 @@ how the subexpression ``(2 + 2)`` is evaluated to normal form before being
8181
bound.
8282

8383
```haskell
84-
(\x. \y. y x) (2 + 2) λx. x + 1
85-
=> (\y. y 4) \x. x + 1
86-
=> (\y. x + 1) 4
84+
(\x. \y. y x) (2 + 2) (\x. x + 1)
85+
=> (\x. \y. y x) 4 (\x. x + 1)
86+
=> (\y. y 4) (\x. x + 1)
87+
=> (\x. x + 1) 4
8788
=> 4 + 1
8889
=> 5
8990
```
@@ -161,17 +162,17 @@ evaluated.
161162
$$
162163
\begin{array}{cl}
163164
\displaystyle \frac{e_1 \to e_1'}{e_1 e_2 \to e_1' e_2} & \trule{E-App} \\ \\
164-
\displaystyle {(\lambda x . e) v \to [x / v] e } & \trule{E-AppLam} \\ \\
165+
\displaystyle {(\lambda x . e_1) e_2 \to [x / e_2] e_1 } & \trule{E-AppLam} \\ \\
165166
\end{array}
166167
$$
167168

168169
For example, the same expression we looked at for call-by-value has the same
169170
normal form but arrives at it by a different sequence of reductions:
170171

171172
```haskell
172-
(\x. \y. y x) (2 + 2) \x. x + 1
173-
=> (\y.y (2 + 2)) λx. x + 1
174-
=> (\x.x + 1) (2 + 2)
173+
(\x. \y. y x) (2 + 2) (\x. x + 1)
174+
=> (\y. y (2 + 2)) (\x. x + 1)
175+
=> (\x. x + 1) (2 + 2)
175176
=> (2 + 2) + 1
176177
=> 4 + 1
177178
=> 5
@@ -388,7 +389,7 @@ s =
388389
```
389390

390391
Evaluation will result in a runtime ``Value`` type, just as before with our
391-
outer interpreters. We will use several "extractor" function which use
392+
outer interpreters. We will use several "extractor" functions which use
392393
incomplete patterns under the hood. The model itself does not prevent malformed
393394
programs from blowing up here, and so it is necessary to guarantee that the
394395
program is sound before evaluation. Normally this would be guaranteed at a
@@ -407,7 +408,7 @@ fromVFun val = case val of
407408
fromVLit :: Value -> Integer
408409
fromVLit val = case val of
409410
VLit n -> n
410-
_ -> error "not a integer"
411+
_ -> error "not an integer"
411412
```
412413

413414
Evaluation simply exploits the fact that nestled up under our existential type
@@ -476,7 +477,7 @@ data Value
476477
fromVEff :: Value -> (IO Value)
477478
fromVEff val = case val of
478479
VEffect f -> f
479-
_ -> error "not a effect"
480+
_ -> error "not an effect"
480481
```
481482

482483
```haskell

chapter6/io.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fromVChar val = case val of
3939
fromVEff :: Value -> (IO Value)
4040
fromVEff val = case val of
4141
VEffect f -> f
42-
_ -> error "not a effect"
42+
_ -> error "not an effect"
4343

4444
lam :: (Value -> Value) -> Value
4545
lam = VFun

chapter6/phoas.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fromVFun val = case val of
1818
fromVLit :: Value -> Integer
1919
fromVLit val = case val of
2020
VLit n -> n
21-
_ -> error "not a integer"
21+
_ -> error "not an integer"
2222

2323
eval :: Expr -> Value
2424
eval e = ev (unExpr e) where

0 commit comments

Comments
 (0)