“Write a function lv: cfg -> (blabel -> ide set), which computes the live variables analysis on the given control flow graph.”
Having cfg and blabel defined and ide set as a list of string, how can I create a function with that signature?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re presumably familiar with the
letsyntax to define a function:You can use this syntax anywhere, including in a function body. Now if you happen to use the inner function’s name as the return value of the outer function, the outer function will be returning a function.
The
letsyntax is in fact syntactic sugar forfunorfunction. In particular, if you defineinner_functionjust to use the name once, you might as well use thefunnotation and not bother giving the inner function a name.Furthermore, if all the outer function does when you pass it an argument is to build and return an inner function, then consider its behavior when you pass that function two arguments. First the outer function builds an inner function, using its first (and only) argument; then that inner function is applied to the second argument, so its body is executed. This is equivalent to having just one function that takes two arguments. This
observation is known as currying.
Note that the type of this function is
int -> int -> int; this is the same type asint -> (int -> int)(the arrow type operator is right-associative).Currying doesn’t apply when the outer function does some work before building the inner function. In that case, the work is performed after receiving the first argument.
So the structure of your code is likely to look like this: