CS141 - Lazy Evaluation (Haskell Runtime Behaviour)

CS141 - Lazy Evaluation (Haskell Runtime Behaviour)

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Are Haskell operators functions?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (17)

Section 1

(17 cards)

Are Haskell operators functions?

Front

Yes!

Back

What do evaluation strategies determine?

Front

The order in which we reduce expressions

Back

What is the call-by-name evaluation strategy?

Front

A non-strict evaluation strategy, whereby expressions are only reduced when their values are needed - i.e. expressions given to functions as arguments are not reduced before the function is called

Back

Give a weakness of the call-by-name evaluation strategy

Front

The same expression may be reduced multiple times

Back

What are free variables?

Front

Variables in scope, but which are not parameters

Back

What is the call-by-value evaluation strategy?

Front

A strict evaluation strategy, whereby all function arguments are reduced to normal forms, which are then passed to the function

Back

What is a redex?

Front

A reducible expression/an expression that can be reduced through function application

Back

What is normal form of an expression?

Front

An expression reduced to an irreducible form

Back

Give a weakness of the call-by-value evaluation strategy

Front

All arguments are evaluated, even if they are not needed

Back

List all the redexes in the below code snippet: fst (1+2, 2+3)

Front

1+2 2+3 fst (1+2, 2+3) (As it is of form fst (x, y) which is reducible)

Back

What is Haskell's evaluation strategy called?

Front

Call by need = Call-by-name + sharing = Lazy evaluation

Back

Why is call-by-name evaluation preferable to call-by-value evaluation for the below code snippet: fst (1+2, 2+3)

Front

It has fewer evaluation steps/operations, as 2+3 (the second tuple value) is never evaluated/reduced

Back

How does the sharing evaluation strategy avoid duplicate evaluation of expressions, as is common in call-by-name evaluation?

Front

The compiler replaces expression arguments with let-bound variables i.e. new variables are created to point to the unevaluated expressions, so that when they are evaluated, they are evaluated in every place that the variable is used

Back

In Haskell, when are redexes needed?

Front

In case expressions

Back

When is a programming language strict?

Front

If the arguments of a function are evaluated before the function is called

Back

What is the name for a reducible expression/an expression that can be reduced?

Front

A redex

Back

What is a closure?

Front

A pointer to some code and containing pointers to free variables i.e. a record storing a function and an environment, where an environment is a map between each free variable of the function and the reference to which the variable is bound

Back