@@ -36,8 +36,8 @@ There are many different models, and various hybrids thereof. We will consider t
36
36
dominant models:
37
37
38
38
* 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
41
41
once and shared upon subsequent references
42
42
43
43
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
81
81
bound.
82
82
83
83
``` 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
87
88
=> 4 + 1
88
89
=> 5
89
90
```
@@ -161,17 +162,17 @@ evaluated.
161
162
$$
162
163
\begin{array}{cl}
163
164
\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} \\ \\
165
166
\end{array}
166
167
$$
167
168
168
169
For example, the same expression we looked at for call-by-value has the same
169
170
normal form but arrives at it by a different sequence of reductions:
170
171
171
172
``` 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 )
175
176
=> (2 + 2 ) + 1
176
177
=> 4 + 1
177
178
=> 5
388
389
```
389
390
390
391
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
392
393
incomplete patterns under the hood. The model itself does not prevent malformed
393
394
programs from blowing up here, and so it is necessary to guarantee that the
394
395
program is sound before evaluation. Normally this would be guaranteed at a
@@ -407,7 +408,7 @@ fromVFun val = case val of
407
408
fromVLit :: Value -> Integer
408
409
fromVLit val = case val of
409
410
VLit n -> n
410
- _ -> error " not a integer"
411
+ _ -> error " not an integer"
411
412
```
412
413
413
414
Evaluation simply exploits the fact that nestled up under our existential type
@@ -476,7 +477,7 @@ data Value
476
477
fromVEff :: Value -> (IO Value )
477
478
fromVEff val = case val of
478
479
VEffect f -> f
479
- _ -> error " not a effect"
480
+ _ -> error " not an effect"
480
481
```
481
482
482
483
``` haskell
0 commit comments