Hacker News new | ask | show | jobs
by tonyg 621 days ago
It's a straightforward syntactic transformation. The two are equivalent. The scope of the rebound variable begins at the rebinding and ends when the surrounding scope ends. Perfectly clear - the only difference is a "let" keyword.

  counter = 0
  ...
  counter = counter + 1
  ...
vs

  let counter = 0 in
  ...
  let counter = counter + 1 in
  ...
1 comments

The ellipses in your straightforward transformation are doing some heavy lifting there. Typically the let…in construct has some way to indicate where the scope of the “in” part ends: indentation (Haskell), explicit “end” marker (SML) etc. Even with that, shadowing does make equational reasoning harder (you have to look at more surrounding context) and should generally be avoided.