Proposal: Improving the IsString String instance
Edward Kmett
ekmett at gmail.com
Sun Aug 25 23:02:10 CEST 2013
On Sun, Aug 25, 2013 at 2:29 PM, Henning Thielemann <
schlepptop at henning-thielemann.de> wrote:
> Am 25.08.2013 17:13, schrieb Edward Kmett:
>
>
> Looks like that takes us back to the original proposal.
>>
>
> It seems that both of Edward and my proposal have a drawback:
> Edward's proposal restricts lists to [Char].
> My proposal allows more element types, but type inference fails for
> (length "abc").
>
> Why is it necessary to let (length "abc") work as is?
>
The issue is that length "abc", splitAt 2 "abc", and dozens of other tools
just stop working for anyone who turns on OverloadedStrings right now.
These users tend to be the users who are most vulnerable from the
standpoint of not knowing what is happening to them. They just see that
Haskell "doesn't work" and go back to Ruby.
IsString was originally put forth as a convenience to make string literals
work with Text, ByteString, directly as a parsing combinator, or as a
variable name or string type in an expression language, but presently that
functionality comes at the tax that random other bits of code in your file
stop working when you turn it on.
My proposal is intended to address this fact, by giving up a subset of
possible convenience instances in exchange for fixing the real headache
this induces for users.
I offer as an example the fact that this even bit us in lens due to the
ubiquitous use of doctest throughout the package. We have to put explicit :set
-XNoOverloadedStrings at the top of any $setup block that uses a string as
an example, because we chose in 2-3 modules to turn on OverloadedStrings to
better showcase how to work with the text and bytestring lenses. doctest
per force recycles the same ghc-api session, as otherwise it takes many
many times longer to run. Every once in a while someone has built a
different subset of the modules in a different order, and we find out we
forgot to turn it off in yet another place. The alternative is that we
clutter literally a few hundred doctests with embedded :: String type
annotations obscuring the very thing they were put in to teach. This was
even worse before we got Simon Hengel to add support for $setup blocks!
-Edward
> Would (length ("abc" :: String)) be too complicated?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130825/b1452c7e/attachment.htm>
More information about the Libraries
mailing list