-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid recursive values should be a compiler error, not a runtime exception #873
Comments
This was referenced Jan 5, 2015
This was referenced May 8, 2015
This was referenced Jul 22, 2015
This was referenced Aug 6, 2015
This was referenced Aug 20, 2015
Closed
This was referenced Oct 24, 2015
This was referenced Nov 22, 2015
This was referenced May 25, 2016
This was referenced Jun 30, 2016
This was referenced Jul 15, 2016
This was referenced Aug 7, 2016
This was referenced Aug 30, 2016
This should be fixed in 0.18 |
Okay, writing something like The link at the end points here. |
rtfeldman
pushed a commit
to rtfeldman/elm-compiler
that referenced
this issue
Nov 19, 2018
This will detect any values defined in terms of themselves without any lambda in the way to delay evaluation. It cannot catch things like “x = (\_ -> x) ()” but at that point you are trying to solve the halting problem, so that is out of scope. Big thanks to the curious person who inadvertently helped me realize how to do this!
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Right now, Elm will not yell at you for writing invalid recursive values like
ones = 1 :: ones
where a value is defined directly in terms of itself. In a strict language like Elm, this means you'd spend an infinite amount of time building the entire structure!Current Behavior
Right now, invalid code like this leads to a runtime exception. In some ways that is better than infinite looping forever, and these exceptions happen very reliably. It is not conditional on anything, you just need to evaluate the code. So it's not awful, but it is also something that beginners run into a decent amount.
Solution
Only permit recursion when there is at least one lambda between the definition and the usage. So
x = x
is not allowed, butfact n = if n <= 0 then 1 else n * fact (n - 1)
is allowed because the definition implicitly introduces a lambda.Timeline
This bug is kind of tricky to resolve, but it is not crazy. From a raw time efficiency standpoint, it is probably best to batch with work on Dead Code Elimination. I find it super annoying when people say "but Elm can have runtime exceptions" as if a compiler bug with a clear resolution is the same as runtime exceptions in JavaScript, so I'd like to do it sooner than DCE if possible.
Other Info
The text was updated successfully, but these errors were encountered: