top | item 41719807

(no title)

xavxav | 1 year ago

What do you mean? let-bindings don't interfere with referential transparency. `let x = 1 in let x = 2 in foo` is referentially transparent.

discuss

order

Izkata|1 year ago

I think you're thinking of shadowing, not re-binding.

kreetx|1 year ago

Yup, as a Haskeller, it's important to remember that rebinding means something else in other languages.

nmadden|1 year ago

The example given in the article is:

    counter = 0
    counter = counter + 1
This is very different to shadowing where there is a clear scope to the rebinding. In this case, I cannot employ equational reasoning within a scope but must instead trace back through every intervening statement in the scope to check whether the variable is rebound.

tonyg|1 year 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
  ...

xavxav|1 year ago

Sure, scopes are not as easily syntactically visible, but each assignment is creating a new scope, that doesn't change anything for equational reasoning which has to account for captures / substitutions anyways.