Hacker News new | past | comments | ask | show | jobs | submit login

The thing which surprised me was not the variable shadowing, rather that the name "item" resovles to different variables on the left and right sides of the :=. This is unusual language design, most languages assign a single meaning to each name in each scope.



It's unusual for the C-style family, but very common in functional languages outside of it, such as the ML family. It's not uncommon to see repeated lines of the form:

   let x = ... x ...
and every such line is a declaration of a new variable that shadows the preceding one.


Not in Haskell at least. What ML language are you thinking of?


I had OCaml in mind, but this is perfectly legal Haskell, too:

   let x = 0 in
   let x = x + 1 in
   ...


fwiw i've also seen this in Rust quite often:

   let foo = foo.clone();
   let bar = bar.into_inner();
   let baz = baz.to_owned();
   let quz = quz.unwrap();
   ...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: