Skip to content
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

Let bindings overriding parameters #829

Closed
jcollard opened this issue Nov 19, 2014 · 7 comments
Closed

Let bindings overriding parameters #829

jcollard opened this issue Nov 19, 2014 · 7 comments

Comments

@jcollard
Copy link

I believe the following should result in 7 but results in 2000.

module Broken where

import Text (asText)


foo a =
    let x = a
        a = 2000
    in x

main = asText (foo 7)
@jcollard
Copy link
Author

@maxsnew
Copy link
Contributor

maxsnew commented Nov 19, 2014

This is because let is mutually recursive. If let acted the way you're saying we'd need a letrec or something to explicitly turn on the mutually recursive version, which needlessly complicates the language, IMO. If you want the behavior you expected you can add another nested let. I'd say this is not a bug.

foo a = let x = a in let a = 2000 in x
main = asText (foo 7)

unfortunately there's a codegen bug with variable shadowing so the code I pasted doesn't work in elm 0.13. Not sure if it's fixed in 0.14.

@jcollard
Copy link
Author

Okay.

I just noticed this as it shows up as bug in the new Random library in core. I'll fix that so it isn't an issue in that library.

Some kind of warning when you do this might be useful. An elm-lint tool would be useful at some point.

@maxsnew
Copy link
Contributor

maxsnew commented Nov 19, 2014

A warning for variable shadowing? Yeah that would be nice, but it's not going to happen unless we expose ADTs and I don't think @evancz wants to be tied down by giving that a public interface.

@mgold
Copy link
Contributor

mgold commented Nov 20, 2014

@maxsnew By ADTs, did you mean ASTs? Because that would make more sense (to me). I think we had talked about AST export, I think in theory it's a good thing to do, but compiler complexity and schedule may well intervene.

@maxsnew
Copy link
Contributor

maxsnew commented Nov 20, 2014

Yeah ASTs, sorry.

@evancz
Copy link
Member

evancz commented Nov 26, 2014

I'll open an issue for "compiler warnings" as a general concept, which should cover this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants