Evaluation Strategies and Termination.pdf

tomatkins 13 views 7 slides Jun 13, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

Evaluation Strategies


Slide Content

Evaluation Strategies and Termination
August 31, 2012

Call-by-name, Call-by-value and termination
You know from the last module that the call-by-name and
call-by-value evaluation strategies reduce an expression to the same
value, as long as both evaluations terminate.
But what if termination is not guaranteed?
We have:
▶If CBV evaluation of an expressioneterminates, then CBN
evaluation ofeterminates, too.
▶The other direction is not true

Non-termination example
Question: Find an expression that terminates under CBN but not
under CBV.

Non-termination
example
Let’s define
deffirst(x:Int, y:Int)=x
and consider the expressionfirst(1, loop).
Under CBN: Under CBV:
first(1, loop) first(1, loop)

Scala’s evaluation strategy
Scala normally uses call-by-value.
But if the type of a function parameter starts with=>it uses
call-by-name.
Example:
defconstOne(x:Int,y:=>Int)=1
Let’s trace the evaluations of
constOne(1+2,loop)
and
constOne(loop,1+2)

Trace ofconstOne(1 + 2, loop)
constOne(1+2,loop)

Trace ofconstOne(loop, 1 + 2)
constOne(loop,1+2)
Tags