I’ve seen that some people are in favor of having the OverloadedString
included in GHC2024.
OverloadedString
allows mainly to use double quote syntax ("like this"
) for Text
(from Data.Text
or Data.Text.Lazy
),but as the name suggests, only override. It doesn’t replace the double quote syntax.
This means that everywhere "I am a text"
can be a Text
or an old plain String
(i.e [Char]
), and sometimes (often?) a doubled quoted thing is ambiguous and you need to force the type usingn type signature of type application.
Including OverloadedString
in GHC2024
will break old code by making lots of double quoted string ambiguous, the easy workaround being not using GHC2024
at all (which defeat the object).
Wouldn’t be better if one could instead of overloading the String syntax, override it and say, going forward "I am a text"
means Text
, unless specified otherwise.
I can see a few options, being able to set a default type to strings, so that with (for example) OverloadedStringDefault Text
-
"text"
is of typeText
- but
"text" :: String
is of typeString
or introducing a new syntax for overloaded and nonoverloaded strings.
What do you think. Is it worth writing a proposal or am I the only one interested by this ?
Update
It look like enabling the ExtendedDefaultRules
(obscure*) extension, might solve the problem.
* I said obscure, because this extension is not listed in the manual in the list of GHC extension but in the GHCi extensions.
More update
ExtendDefaultRules
solves the problem in way but creates another one. ExtendedDefaultRules
can be set per project (as OverloadedString
) but (unless I am wrong) default rules are per file.
The combinaison of OverloadedSting
and ExtendDefaultRules
per project might result in String being chosen without any warning (even though Text would have been prefered for efficiency).
An example is for example parsing a csv or some JSon and having some code like
t <- get "high/low"
case t of
"low" -> Low
"hight" -> High
...