-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path05 Notes Function BIndings.sml
25 lines (15 loc) · 1.06 KB
/
05 Notes Function BIndings.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(* function bindings *)
(* a function is a value
the function is added to the environment so later expressions can call it.
the body of a function is type-cheked, and the following are included in the static enviornment
- the enclosing or earlier static bindings
- the arguments to the function and their types, THEY ARE ADDED IN THE STATIC ENV ONLY FOR THE BODY OF THE FUNCTION, NOT FOR LATER
- the function func x0 : ( t1 * t2 * ... * tn) -> t, for recursion *)
(* in SML functions can't take variable number of arguments
after syntax check for a function call, we have typechecking
example, a function call e0 ( e1,.., en), e0 has to have the type (t1 * .. * tn) -> t
While evalutating: look up the function in the dynamic environment.
Expand the function call to a function. (this had already type-checked from before)
Evaluate the expression using the arguments
'The result is evaluation of the expression in the dynamic environment, extended to map the
values being passed to the the variables of the function *)