{"action":"created","issue":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/905","labels_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/905/labels{/name}","comments_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/905/comments","events_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/905/events","html_url":"https://github.com/elm-lang/elm-compiler/issues/905","id":65246011,"number":905,"title":"Proposal: String Interpolation","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},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":49,"created_at":"2015-03-30T16:06:45Z","updated_at":"2016-01-07T13:09:30Z","closed_at":null,"body":"[String interpolation](http://en.wikipedia.org/wiki/String_interpolation) is incredibly desirable when building UIs. It would be great if Elm had it!\r\n\r\n## Proposed Implementation\r\n\r\n**1.** New interpolation syntax is introduced for `\"` and `\"\"\"` strings:\r\n\r\n```elm\r\n\"There are {{length hobbitList}} hobbits.\"\r\n\"\"\"There are {{length hobbitList}} hobbits.\"\"\"\r\n\r\n-- both desugar to the following:\r\n\"There are \" ++ (toString (length hobbitList)) ++ \" hobbits.\"\r\n```\r\n**2.** Extra whitespace surrounding the expression inside the `{{ }}` is ignored; the following are equivalent:\r\n\r\n```elm\r\n\"There are {{numHobbits}} hobbits.\"\r\n\"There are {{ numHobbits }} hobbits.\"\r\n\"\"\"There are {{numHobbits}} hobbits.\"\"\"\r\n\"\"\"There are {{ numHobbits }} hobbits.\"\"\"\r\n\"There are \" ++ (toString numHobbits) ++ \" hobbits.\"\r\n```\r\n\r\n**3.** When you do not want interpolation, you can escape with a backslash like so:\r\n\r\n```elm\r\n\"There are \\{{length hobbitList}} hobbits.\"\r\n\"\"\"There are \\{{length hobbitList}} hobbits.\"\"\"\r\n\r\n-- both desugar to the same string without the backslashes; no interpolation is performed.\r\n```\r\n\r\n**4.** Aside from the escaping noted above, there would be no special syntax for a \"noninterpolated string\" for [these reasons](https://github.com/elm-lang/elm-compiler/issues/905#issuecomment-89046859).\r\n\r\n**5.** `toString` is changed such that when it is given a `String`, it just returns the argument it was given. (Currently it would wrap that argument in quotation marks.)\r\n\r\n## Background\r\nThere are a bunch of [examples of how this is done in various languages](http://en.wikipedia.org/wiki/String_interpolation#Examples) on Wikipedia. Here are some different ways we could make the following Elm code more concise using String interpolation.\r\n\r\n(Note: I'm assuming `toString` is changed to be the identity function when given a String.)\r\n\r\n**[Elm](http://package.elm-lang.org/packages/elm-lang/core/1.1.1/String)**:\r\n```elm\r\n\"There are \" ++ (toString (length hobbitList)) ++ \" hobbits.\"\r\n```\r\n\r\n**[Mustache](https://mustache.github.io/mustache.5.html)/[Handlebars](http://handlebarsjs.com/)**:\r\n```handlebars\r\n\"There are {{length hobbitList}} hobbits.\"\r\n```\r\n\r\n**[Ruby](https://rubymonk.com/learning/books/1-ruby-primer/chapters/5-strings/lessons/31-string-basics)/[CoffeeScript](http://coffeescript.org/#strings)/[Elixir](http://elixir-lang.org/getting-started/basic-types.html#strings):**\r\n```ruby\r\n\"There are #{length hobbitList} hobbits.\"\r\n```\r\n\r\n**[Perl](http://perlmaven.com/quoted-interpolated-and-escaped-strings-in-perl)/[PHP](http://php.net/manual/en/language.types.string.php#language.types.string.parsing.simple)/[Dart](https://www.dartlang.org/docs/dart-up-and-running/ch02.html)/[Haxe](http://haxe.org/manual/lf-string-interpolation.html)/[ES6 JavaScript](http://updates.html5rocks.com/2015/01/ES6-Template-Strings)**:\r\n```dart\r\n\"There are ${length hobbitList} hobbits.\"\r\n```\r\n\r\n**[Swift](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-ID292)**:\r\n```swift\r\n\"There are \\(length hobbitList) hobbits.\"\r\n```\r\n\r\n**[Boo](http://boo.codehaus.org/String+Interpolation)**:\r\n```boo\r\n\"There are $(length hobbitList) hobbits.\"\r\n```\r\n\r\n**[Scala](http://docs.scala-lang.org/overviews/core/string-interpolation.html):**\r\n```scala\r\ns\"There are ${length hobbitList} hobbits.\"\r\n```\r\n\r\n**[C#](https://roslyn.codeplex.com/discussions/570614):**\r\n```c#\r\n$\"There are {length hobbitList} hobbits.\"\r\n```"},"comment":{"url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/comments/169659427","html_url":"https://github.com/elm-lang/elm-compiler/issues/905#issuecomment-169659427","issue_url":"https://api.github.com/repos/elm-lang/elm-compiler/issues/905","id":169659427,"user":{"login":"dennisreimann","id":886,"avatar_url":"https://avatars.githubusercontent.com/u/886?v=3","gravatar_id":"","url":"https://api.github.com/users/dennisreimann","html_url":"https://github.com/dennisreimann","followers_url":"https://api.github.com/users/dennisreimann/followers","following_url":"https://api.github.com/users/dennisreimann/following{/other_user}","gists_url":"https://api.github.com/users/dennisreimann/gists{/gist_id}","starred_url":"https://api.github.com/users/dennisreimann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dennisreimann/subscriptions","organizations_url":"https://api.github.com/users/dennisreimann/orgs","repos_url":"https://api.github.com/users/dennisreimann/repos","events_url":"https://api.github.com/users/dennisreimann/events{/privacy}","received_events_url":"https://api.github.com/users/dennisreimann/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T13:09:30Z","updated_at":"2016-01-07T13:09:30Z","body":"Came here looking for how to do string interpolation in Elm. After reading this issue (and other ones across the Elm repos) I just wanted to say how nice it is to read discussions like this, because it ensures me that Elm is well worth learning and that it has a friendly community that's trying to shape the language nicely. :+1:"}}