default instance for IsString
Markus Läll
markus.l2ll at gmail.com
Tue Apr 24 10:17:52 CEST 2012
I see what you mean -- many libraries provide conveniences like that
(like TagSoups `takeWhile (~== "</a>") tags' and so on). But that's
the inherent mismatch between a String-- a unicode literal --and
whatever else you want it to be, be it ASCII or bash or XML or
something else.. I think the answer to them all is to use TH (as
already suggested :-).
A similar issue is printf, which handles the errors at runtime (though
I think there's a TH solution already existing for that).
On Tue, Apr 24, 2012 at 10:58 AM, Yitzchak Gale <gale at sefer.org> wrote:
> Markus Läll wrote:
>> What can go wrong when you use an overloaded string to be fromString'd
>> into Text?
>
> Here's an example:
>
> The author of the xml-types package provides an IsString
> instance for XML names, so you can conveniently
> represent XML names as string literals in your source
> code.
>
> But not every string is a valid XML name. If you mistype
> the literal, your program will still compile. It may even run
> for a while. But when someone uses your program in
> a way that causes that mistyped XML name literal
> to be resolved, your program will likely crash, unless you
> structured it in a way that allows that XML name literal
> to be wrapped in an appropriate exception handler in the
> IO monad.
>
> -Yitz
--
Markus Läll
More information about the Glasgow-haskell-users
mailing list