elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Shadowing should not be prohibited by the compiler #2239

Open MartinErwig opened 2 years ago

MartinErwig commented 2 years ago

Quick Summary:

The following example is rejected by the Elm compiler (0.19.1):

let x=1 in x+let x=2 in x

The REPL says "These variables cannot have the same name". I think it's fine for the compiler to issue a warning, but the expression has a perfectly well-defined semantics, and it is wrong for the compiler to reject it simply based on a stylistic argument.

Why do I (and others) care? I want to use Elm to teach about programming languages. And nested let expressions with the same name are a good way to talk about the concept of variable scope. The unnecessarily restrictive behavior of the Elm compiler prevents that.

Turning the compiler error about shadowing into a warning would address this problem.

SSCCE

github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

adamdicarlo commented 1 year ago

before Elm 0.19, accidental shadowing tripped me up a lot while learning Elm (outside of the REPL).

Seems like allowing it in the REPL with a command-line option would be useful, though!