fun f x =
let
fun g y = x + y
in
g
end;
Fails since a dynamically allocated stack of activation records plus nesting links will not accommodate the return value of a function which requires the use of values from the containing function.
For the following ML function, could the activation record for the function be deallocated as soon as the function returns? Explain why or why not.
fun f x = fn y => x + y;
No as it returns a function which in turn uses the parameter to the original function as a variable.
The following ML function contains a function call that passes a function parameter f
. Will the function f
use its nesting link when called? Explain (Assume that the nesting link is not used to resolve references to predefined operators (like +) and functions (like map
).)
fun addall n theList =
let fun f x = x + n;
in map f theList
end;
Yes it does use its nesting link in order to find the value of the variable n.