Dear committee,
In
#570, Brandon Chinn proposes adding native string interpolation syntax to GHC, along the lines of s"a ${x + 1} b", catching up with and even exceeding similar features in popular programming languages.
The desugaring of s"a ${x + 1} b" is:
```
Data.String.Interpolate.Experimental.interpolateString
( \convert raw append empty ->
raw "a "
`append` convert (x + 1)
`append` raw " b"
`append` empty
)
:: String
```
where the following definitions are added to ghc-experimental:
```
class Interpolate a where
interpolate :: a -> String
type SimpleStringInterpolator s =
( forall ss.
(forall a. Interpolate a => a -> s)
-> (s -> s)
-> (s -> ss -> ss)
-> ss
-> ss
)
-> s
interpolateString :: (IsString s, Monoid s) => SimpleStringInterpolator s
interpolateString f = mconcat $ f (fromString . interpolate) id (:) []
```
With -XQualifiedStrings, the string interpolation function may be rebound as well:
```
SQL.s"select * from users where name = ${Text.toUpper name} and age = ${age}"
-- desugars to
SQL.interpolateString $ \convert raw append empty ->
raw "select * from users where name = "
`append` convert (Text.toUpper name)
`append` raw " and age = "
`append` convert age
`append` empty
```
I think this is an important proposal and I would emphatically accept one form or anothter.
It is a useful feature with a long history of continued refinement by Brandon.
I would sacrifice generality and implement a simpler expansion instead, such as
```
mconcat
[ fromString "a "
, interpolate (x + 1)
, fromString "b"
]
:: String
```
So I abstain from voting for the particular version of the proposal.
Cheers,
Sebastian