default instance for IsString

Gábor Lehel illissius at gmail.com
Wed Apr 25 19:29:55 CEST 2012


On Wed, Apr 25, 2012 at 11:39 AM, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> One can always use a Maybe to make an IsString literal total. Perhaps this
> is what library authors should do in those cases when a fromString
> implementation is obviously partial.
>
> i.e. instead of instance IsString XML where ...
> define: instance IsString (Maybe XML) where ...
>
> HTH,
> Ozgur

This sounds sensible, but then you'll have to handle the Nothing case
of the Maybe. There you are, writing a literal, and also writing
fallback code specifying what should be done in case you messed up
when writing the literal. What can you reasonably write there, other
than error "oops, I wrote a bad literal"? You're back where you
started.

There's not much you can do about programmer error at runtime except
abort, which is why you'd really prefer to have it checked at compile
time. But unless you write a quasiquoter, runtime checking might be
your only option, and at that point whether you prefer convenience or
explicitness seems like a question of taste, because the important bad
thing (runtime assertions) you're already stuck with.



More information about the Glasgow-haskell-users mailing list