compiler icon indicating copy to clipboard operation
compiler copied to clipboard

Shadowing should not be prohibited by the compiler

Open MartinErwig opened this issue 3 years ago • 2 comments

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

  • Elm: 0.19.1, REPL

MartinErwig avatar Jan 15 '22 17:01 MartinErwig

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Jan 15 '22 17:01 github-actions[bot]

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!

adamdicarlo avatar Sep 01 '22 22:09 adamdicarlo