I have a little trouble understanding the evaluation of function bindings and function calls in SML.
A simple example of a function binding and a function call:
val w = 12;
fun pow(x:int,n:int) =
if n = 0
then 1
else x * pow(x,n-1)
pow((1+1),3);
A little theory:
Formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller. In the above function binding, the formal arguments are x and n.
Actual parameter — the actual value that is passed into the method by a caller.
In the function call below, the actual arguments are (1+1) and 3.
My two questions:
1.) When we type-check function bindings, we store, in the static environment, the types of earlier declarations, types of function arguments and the functions type, so it looks something like this:
[w=int, x=int, n=int, pow=int*int->int]
Now to the evaluation. It says here (on slide 6) that the variable "pow" is added to the dynamic environment. I'm a little confused about this. Shouldn't it store the whole function binding, so the dynamic environment would look something like this?
[pow = whole function body]
2.)When we call the function above we pass the actual parameters (1+1) and 3 to the pow function. I've read that after these expressions are evaluated ( 1+1 = 2 and 3 = 3) the values are assigned
to the formal parameters. What type of parameters is then actually used for the evaluation of a function call, if the values are assigned to the formal parameters? By definition, the formal parameters shouldn't have much to do with this.
Thank you in advance for your help.
EDIT: found the page, which says, that the evaluated actual parameters are assigned to the formal parameters in the method's definition.