{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/elm-plans/issues/12","labels_url":"https://api.github.com/repos/elm-lang/elm-plans/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/elm-plans/issues/12/comments","events_url":"https://api.github.com/repos/elm-lang/elm-plans/issues/12/events","html_url":"https://github.com/elm-lang/elm-plans/issues/12","id":96375220,"number":12,"title":"Proposal: Add Array, Dict, Set Literal Syntax","user":{"login":"TheSeamau5","id":3227869,"avatar_url":"https://avatars.githubusercontent.com/u/3227869?v=3","gravatar_id":"","url":"https://api.github.com/users/TheSeamau5","html_url":"https://github.com/TheSeamau5","followers_url":"https://api.github.com/users/TheSeamau5/followers","following_url":"https://api.github.com/users/TheSeamau5/following{/other_user}","gists_url":"https://api.github.com/users/TheSeamau5/gists{/gist_id}","starred_url":"https://api.github.com/users/TheSeamau5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheSeamau5/subscriptions","organizations_url":"https://api.github.com/users/TheSeamau5/orgs","repos_url":"https://api.github.com/users/TheSeamau5/repos","events_url":"https://api.github.com/users/TheSeamau5/events{/privacy}","received_events_url":"https://api.github.com/users/TheSeamau5/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-07-21T17:44:59Z","updated_at":"2015-07-22T01:45:35Z","closed_at":null,"body":"Inspired by [Clojure's collection literals](http://clojure.org/reader), I propose to add support for Array, Dict, and Set literals (analogous to List syntax).\r\n\r\n#### Proposed syntax\r\n\r\n**Array**\r\n```elm\r\narray = \r\n  #[1, 2, 3]\r\n```\r\n\r\nRationale: Looks like a list but with a hash sign.\r\n\r\n**Dict**\r\n```elm\r\ndict = \r\n  #{ \"key1\" : \"value1\"\r\n   , \"key2\" : \"value2\"\r\n   , \"key3\" : \"value3\"\r\n   }\r\n```\r\n\r\nRationale: Looks like Json. In spirit, Dicts and Json serve the same purpose--to store key-value data.\r\n\r\n**Set**\r\n```elm\r\nset = \r\n  #{1, 1, 2, 3, 2}\r\n```\r\n\r\nRationale: While we're at it, why not? I mean... Clojure does it.\r\n\r\n\r\nIn all cases, the main goal of the syntax is to encourage the usage of these datastructures, which have advantages that linked lists don't. Arrays have fast access, setting, and efficient appending to the end. Dicts are perfect for storing key-value data. Sets guarantee that there are no duplicates (therefore, no need to filter out all duplicates from a list).\r\n\r\nCurrently, if you want to write a DSL in Elm (like elm-html), lists and records are your only tools. The downside of this is that lists may not be the optimal data structure for your DSL.\r\n\r\nFor example, here is how elm-html would look with arrays and dicts\r\n\r\n```elm\r\ndiv \r\n  #[ style #{ \"position\" : \"absolute\" , \"color\" : \"red\" } \r\n   , id \"containerDiv\" \r\n   ]\r\n  #[ ul #[]\r\n      #[ li #[] #[text \"Hello\"]\r\n       , li #[] #[text \"World\"]\r\n       ]  \r\n   ] \r\n```"},"comment":{"url":"https://api.github.com/repos/elm-lang/elm-plans/issues/comments/123527278","html_url":"https://github.com/elm-lang/elm-plans/issues/12#issuecomment-123527278","issue_url":"https://api.github.com/repos/elm-lang/elm-plans/issues/12","id":123527278,"user":{"login":"TheSeamau5","id":3227869,"avatar_url":"https://avatars.githubusercontent.com/u/3227869?v=3","gravatar_id":"","url":"https://api.github.com/users/TheSeamau5","html_url":"https://github.com/TheSeamau5","followers_url":"https://api.github.com/users/TheSeamau5/followers","following_url":"https://api.github.com/users/TheSeamau5/following{/other_user}","gists_url":"https://api.github.com/users/TheSeamau5/gists{/gist_id}","starred_url":"https://api.github.com/users/TheSeamau5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheSeamau5/subscriptions","organizations_url":"https://api.github.com/users/TheSeamau5/orgs","repos_url":"https://api.github.com/users/TheSeamau5/repos","events_url":"https://api.github.com/users/TheSeamau5/events{/privacy}","received_events_url":"https://api.github.com/users/TheSeamau5/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T01:45:35Z","updated_at":"2015-07-22T01:45:35Z","body":"@mgold I didn't give the example of elm-html to claim that arrays were superior to lists. What I mean, is that there a number of cases where they are the better structure. \r\n\r\nFor example:  Infinite scrolling lists. You need a collection that can store all that information, send actions uniquely to the concerned element, and slice the collection appropriately to only display what is visible. Arrays beat lists on all these fronts.\r\n\r\nWhile you can implement the described behaviors with Arrays today, you end up paying a needless conversion to lists. Why? It's completely unnecessary. \r\n\r\nAgain, in the particular context of elm-html, I am not advocating the change from lists and tuples to arrays and dicts. What I am pointing out is what @rtfeldman pointed out. The reason elm-html took the routes of lists and tuples is not due to a calm, thoughtful analysis of performance tradeoffs. It is uniquely because lists and tuples have associated literals. Arrays and Dicts do not. Currently, if you want to make a DSL, using Arrays or Dicts or Sets are out of the question, even if they would be ideal data structures for these DSLs. \r\n"}}