NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX

From call-by-value to call-by-name

Now that we have all the machinery available to delay the evaluation of expressions we may ask whether a call-by-name variant can always be found for an existing call-by-value function. This question can be answered positively and we will now sketch out a recipe. Consider a function f with the following form:

fun f x = ... x ... x ...
and assume that this function has type X -> Y. We can provide a call-by-name variant which has type X delayed -> Y where every occurrence of x is replaced by force(x):
fun f x = ... (force(x)) ... (force(x)) ...
finally replace any applications of the function, f(exp), by f( fn () => exp).

NEXT ·  UP ·  PREVIOUS ·  CONTENTS ·  INDEX