Shadowing and Nested function

Your code is equivalent to the following, where I’ve simply numbered instances of your names to help you visualize how shadowing is occurring.

let func y0 = 
  let dup0 y1 = y1 + y1
  let z0 = dup0 y0
  let dup1 y2 = 
    let dup2 z1 = 
      let y3 = y2 * z1 
      y3
    let z2 = y2 
    y2 
  dup1 z0 + z0

This can be further simplified, of course. Since dup2 and z2 are never used, dup1 is equivalent to let dup1 y2 = y2, and the whole function is equivalent to

let func y0 =
  let dup0 y1 = y1 + y1
  let z0 = dup0 y0
  dup1 z0 + z0

Which is equivalent to

let func y0 =
  let z0 = y0 + y0
  z0 + z0

by substitution. This is the same as

let func y0 = 4 * y0

Does this help?

Leave a Comment