{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/981","labels_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/981/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/981/comments","events_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/981/events","html_url":"https://github.com/elm-lang/elm-compiler/issues/981","id":93309579,"number":981,"title":"Proposal: lamba-bind with = not ->","user":{"login":"mgold","id":1191970,"avatar_url":"https://avatars.githubusercontent.com/u/1191970?v=3","gravatar_id":"","url":"https://api.github.com/users/mgold","html_url":"https://github.com/mgold","followers_url":"https://api.github.com/users/mgold/followers","following_url":"https://api.github.com/users/mgold/following{/other_user}","gists_url":"https://api.github.com/users/mgold/gists{/gist_id}","starred_url":"https://api.github.com/users/mgold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgold/subscriptions","organizations_url":"https://api.github.com/users/mgold/orgs","repos_url":"https://api.github.com/users/mgold/repos","events_url":"https://api.github.com/users/mgold/events{/privacy}","received_events_url":"https://api.github.com/users/mgold/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-06T15:36:40Z","updated_at":"2015-07-07T21:32:25Z","closed_at":null,"body":"Since we seem to be making syntax proposals (#978, #979) I thought I'd throw this into the ring. Although I think it is a mostly orthogonal change, it would certainly be best to group all breaking syntax changes into a single release.\r\n\r\nMy primary motivation is consistency, which has a practical benefit. A few months ago, my employer unexpectedly introduced Clojure and many of my coworkers (Rails devs) were struggling. One piece of advice I found very helpful was to say, \"open paren means function application\". (Let's not get pedantic about the threading macro.) Having a consistent syntactic construct seems, empirically (though hardly scientifically) to help people work their way into a functional language. It's important that the construct be a bijection: function application occurs if _and only if_ you see an open paren.\r\n\r\nWith that in mind, I present the five ways of binding a value to a name in Elm 0.15:\r\n```elm\r\n-- top level definitions\r\ndouble x = 2*x\r\n\r\n-- records\r\naRecord = {x = 4}\r\nanotherRecord = {aRecord | x2 = aRecord.x * 2}\r\n\r\n-- let\r\ndouble' x =\r\n    let doubled = x*2\r\n    in doubled\r\n\r\n-- union types and type aliases\r\n-- we're binding a type to a capitalized name of a type, so this is still consistent\r\ntype Foo = Bar | Qux\r\ntype alias Point = { x : Float, y : Float }\r\n\r\n-- lambda\r\ndouble'' = \\x -> 2*x\r\n````\r\n\r\nDo you see the problem? Lambda bindings are unique in that they use `->` instead of `=`. This means that I can't truthfully say, \"equals sign means the name on the left is being bound to the value on the right\". Yes, this is true for lambdas, provided we change the syntax: the function that takes x, `\\x`, is being bound to `x*2`, and `x` itself is being bound to whatever you pass the function.\r\n\r\nFurthermore, I also can't say \"right arrow means case analysis\". Both `case` and multi-way `if` use the `->` arrow, and that's good. (I support removing the pipes from the multi-way if to match case, but that is covered in other proposals.) Because of lambda bindings, the `->` symbol is used in a context completely devoid of case analysis. (It's good that there's no `->` in the single-way if; case analysis implies multiple cases! With lambda, it's possible to do _unsafe_ case analysis like `\\(Just x) -> x` but we shouldn't encourage this. The only legitimate use for unwrapping a union type in an argument list is when there is only one tag.)\r\n\r\nIncidentally, Elm is really good about using `:` to mean only \"has type\", in annotations (top-level and let-bound) and in record type aliases. I think many JS programmers will gravitate towards writing record _terms_ with colons, JSON style. One way to head that off is to use colon to mean has-type (done), _and_ to have a clear symbol that means binding instead (this proposal).\r\n\r\nTo be explicit, the proposed change is to write `\\x y z = code` rather than `\\x y z -> code`.\r\n\r\nI think implementing this will be a simple change to the parser, perhaps [here](https://github.com/elm-lang/elm-compiler/blob/3d63f8270d4db2f7528844ac2468a9fe6f87e8ff/src/Parse/Expression.hs#L271). The larger task will be all the code that breaks in the examples, docs, and third-party libs. One possibility is to accept either `\\x -> 2*x` or `\\x = 2*x` in a 0.15.x release, but provide a deprecation notice on the previous one.\r\n\r\nAside from the difficulty of switching, there doesn't seem to be a reason to stick with the `->` syntax other than a hold-over from Haskell (and maybe ML, I'd have to check). I'm interested in what you have to think about this proposal."},"comment":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/comments/119348587","html_url":"https://github.com/elm-lang/elm-compiler/issues/981#issuecomment-119348587","issue_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/981","id":119348587,"user":{"login":"dobesv","id":327833,"avatar_url":"https://avatars.githubusercontent.com/u/327833?v=3","gravatar_id":"","url":"https://api.github.com/users/dobesv","html_url":"https://github.com/dobesv","followers_url":"https://api.github.com/users/dobesv/followers","following_url":"https://api.github.com/users/dobesv/following{/other_user}","gists_url":"https://api.github.com/users/dobesv/gists{/gist_id}","starred_url":"https://api.github.com/users/dobesv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dobesv/subscriptions","organizations_url":"https://api.github.com/users/dobesv/orgs","repos_url":"https://api.github.com/users/dobesv/repos","events_url":"https://api.github.com/users/dobesv/events{/privacy}","received_events_url":"https://api.github.com/users/dobesv/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T21:32:25Z","updated_at":"2015-07-07T21:32:25Z","body":"That said I see your point about `=` being possibly more consistent with other binding constructs.  However, I'm not sure it's a significant improvement over the consistency with mathematics, and consistency with other languages is worth something, too.  I'd probably vote in favor of the status quo."}}