default instance for IsString

Yitzchak Gale gale at sefer.org
Tue Apr 24 09:22:56 CEST 2012


Michael Snoyman wrote:
> Here's a theoretically simple solution to the problem. How about
> adding a new method to the IsString typeclass:
>    isValidString :: String -> Bool
> ...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 approach does address the real reason that
OverloadedStrings is unsafe in practice: library authors
sometimes feel that they must reject certain strings.
This gives them a safer outlet for that, with a nice
simple API.

However, it requires GHC to be able to resolve the
monomorphic type of the string literal at a time
when it can get its hands on the appropriate
isValidString method, already compiled, and call it.
Seems like in GHC, at least, the implementation
of that would have to involve some kind of TH magic
in the background. Is this possible?

Thanks,
Yitz



More information about the Glasgow-haskell-users mailing list