Intermediate
Compilers & Programming Language Theory
Q79 / 100
What is the purpose of a thunk in lazy or call-by-name evaluation?
Correct! Well done.
Incorrect.
The correct answer is C) A suspended, unevaluated computation paired with its environment, which is forced (evaluated) only when its value is actually required, and whose result may then be cached for reuse
C
Correct Answer
A suspended, unevaluated computation paired with its environment, which is forced (evaluated) only when its value is actually required, and whose result may then be cached for reuse
Explanation
In lazy languages such as Haskell, binding a name to an expression does not immediately compute it; instead a thunk wraps the expression. The first time the value is demanded, the thunk is evaluated and, in call-by-need semantics, the result replaces the thunk so subsequent uses are free.
Progress
79/100