This function is specially obfuscated, so lets move carefully over the reduction steps:
let f y =
let z = (let x = 5 in y * x) + y in "hello" in (f 7) ^ " world"
==>
let f y =
let z = y * 5 + y in "hello" in (f 7) ^ " world"
==>
let f y =
let z = y * 5 + y in "hello" in (f 7) ^ " world"
At this point is obvious, that z
is unused in function f
, let's remove it:
let f y = "hello" in (f 7) ^ " world"
We can see, that actually we have the "function" f
, that always returns "hello":
let f y = "hello"
That is defined in the scope of the expression (f 7) ^ " world"
. f 7
is evaluated to "hello"
, and we have "hello world"
.
The
let <name> = <expr-1> in <expr-2>
has the following rules of evaluation:
- evaluate
<expr-1>
- substitute each free occurrences of
<name>
in <expr-2>
with <expr-1>
- evaluate
<expr-2>