default instance for IsString

Michael Snoyman michael at
Tue Apr 24 08:32:27 CEST 2012

On Tue, Apr 24, 2012 at 9:26 AM, Yitzchak Gale <gale at> wrote:
> Greg Weber wrote:
>> I very much agree with you. However, when we complain about something
>> essentially we are asking others to prioritize it ahead of other
>> things. I don't think any more visibility of this issue is going to
>> improve its prioritization. I suspect your only way forward right now
>> is to start implementing something yourself.
> You're right. But as a professional Haskell developer, I am
> under the same kinds of deadline pressures as any other
> professional. So I'm afraid it's not going to be me, at least
> not in the near future.
> However, what I can do is raise the red flag. Some people
> are pushing things in directions which would cause
> OverloadStrings to become more and more ubiquitous,
> perhaps even the default. I want to make sure that the
> people who are doing that are aware of the deep problems
> with that approach.
> Sure, as much as anyone else, I want string literals
> that can be typed as Text. But not at the cost of
> delaying syntax checking to run time.
>  And, as Bas points out, that there are many different
> compile time mechanisms that could be used for this.
> Thanks,
> Yitz

Here's a theoretically simple solution to the problem. How about
adding a new method to the IsString typeclass:

    isValidString :: String -> Bool

We can give it a default implementation of `const True` for backwards
compatibility. Then, whenever GHC applies OverloadedStrings in a case
where the type is fully known at compile time (likely the most common
case), it can run the check and- if it returns False- stop the
compile. This has the benefits of letting existing code continue to
work unchanged, and not requiring any Template Haskell to be involved.

A downside is that it will still let invalid code through sometimes.
Perhaps a solution is to modified the OverloadedStrings extension that
requires that the type be fully known. If someone *really* wants
polymorphic strings, they can explicitly add `fromString`. I actually
think I'd prefer this version.


More information about the Glasgow-haskell-users mailing list