{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/985","labels_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/985/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/985/comments","events_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/985/events","html_url":"https://github.com/elm-lang/elm-compiler/issues/985","id":94366715,"number":985,"title":"Proposal: remove record syntax for field addition and field deletion","user":{"login":"evancz","id":1658058,"avatar_url":"https://avatars.githubusercontent.com/u/1658058?v=3","gravatar_id":"","url":"https://api.github.com/users/evancz","html_url":"https://github.com/evancz","followers_url":"https://api.github.com/users/evancz/followers","following_url":"https://api.github.com/users/evancz/following{/other_user}","gists_url":"https://api.github.com/users/evancz/gists{/gist_id}","starred_url":"https://api.github.com/users/evancz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evancz/subscriptions","organizations_url":"https://api.github.com/users/evancz/orgs","repos_url":"https://api.github.com/users/evancz/repos","events_url":"https://api.github.com/users/evancz/events{/privacy}","received_events_url":"https://api.github.com/users/evancz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-07-10T18:40:38Z","updated_at":"2015-07-10T21:47:15Z","closed_at":null,"body":"The idea is to remove the following syntax:\r\n\r\n```elm\r\n{ point - z }      -- remove field z\r\n\r\n{ point | z = 4 }  -- add field z\r\n```\r\n\r\nWe keep all the type system stuff that makes record update work, but this surface syntax is removed.\r\n\r\nI created the [simple-records](https://github.com/elm-lang/elm-compiler/tree/simpler-records) branch which actually implements this.\r\n\r\nTalking with @JoeyEremondi, it came up that these operations may impose a significant performance cost. I had a discussion along these lines with one of the creators of Julia at Curry On which kind of pushed me over on this.\r\n\r\n## Arguments in favor of removal\r\n\r\n**Usage:** I have never seen either of these features used in practice. Furthermore, the uses that I have seen are crazy and cool (see @Apanatshka's example [here](https://groups.google.com/forum/#!searchin/elm-discuss/jeff$20stack$20records/elm-discuss/jDLMf1ux2Vw/yusfiivMUuYJ)) but in a way that I'd probably recommend against in general :)\r\n\r\nI also suspect there's something antimodular about this in that you can add a field `x` to any record, even one that already has an `x`. This issue has never come up in practice (since no one uses this) but it's something to think about.\r\n\r\n**Performance:** The fact that you can add and remove fields in JS was a big part of why performance was terrible back before Chrome came along and started mapping things onto \"static classes\" as much as possible (i.e. fixed set of fields so that lookups are constant time)\r\n\r\nWe piggy back on their work for this, but this will not be true if we are compiling to assembly some day. The ideal case is that we know the exact shape of a record, so we'd have the following code gen:\r\n\r\n```elm\r\n-- elm\r\npoint = { x = 0, y = 0, z = 0 }\r\nnewPoint = { point | x <- 4 }\r\n```\r\n```javascript\r\n// generated js\r\nvar point = { x: 0, y: 0, z: 0 };\r\nvar newPoint = { x: 4, y: point.y, z: point.z }\r\n```\r\n\r\nThis may mean we can just copy the bits when we are going lower level. Furthermore, when you are doing field lookup, the fastest way is if you know the offset of each field so that lookup time is constant: `r.x` becomes \"get offset N in `r`\" and I think this will be harder if we have extension. We'll at least have to do a bunch of work, and it's all for a feature that seems not too useful so far.\r\n\r\n## Remaining Questions\r\n\r\nOkay, this is a distraction. It does not change the core idea at all, but it's the part of this proposal that is the most controversial.\r\n\r\nNow that `=` is free, maybe it makes sense to use that for record updates. In other words, should we switch from `<-` to `=`?\r\n\r\nLet's talk about this only to the extent that it touches on the broader question."},"comment":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/comments/120537020","html_url":"https://github.com/elm-lang/elm-compiler/issues/985#issuecomment-120537020","issue_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/985","id":120537020,"user":{"login":"rtfeldman","id":1094080,"avatar_url":"https://avatars.githubusercontent.com/u/1094080?v=3","gravatar_id":"","url":"https://api.github.com/users/rtfeldman","html_url":"https://github.com/rtfeldman","followers_url":"https://api.github.com/users/rtfeldman/followers","following_url":"https://api.github.com/users/rtfeldman/following{/other_user}","gists_url":"https://api.github.com/users/rtfeldman/gists{/gist_id}","starred_url":"https://api.github.com/users/rtfeldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtfeldman/subscriptions","organizations_url":"https://api.github.com/users/rtfeldman/orgs","repos_url":"https://api.github.com/users/rtfeldman/repos","events_url":"https://api.github.com/users/rtfeldman/events{/privacy}","received_events_url":"https://api.github.com/users/rtfeldman/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T21:47:15Z","updated_at":"2015-07-10T21:47:15Z","body":"@evancz We chatted about it briefly at the end of [this comment](https://github.com/elm-lang/elm-compiler/issues/984#issuecomment-120177358) and the two after it, but did not come up with any solutions.\r\n\r\nI proposed a pipe-dream-ish \"best of all worlds\" solution [just now](https://github.com/elm-lang/elm-compiler/issues/984#issuecomment-120536939), but I suspect it may be impossible."}}