
I wrote:
I noticed when looking at the IsString instance for Name: it can introduce crashes into a program if someone accidentally puts a '{' at the beginning of a Name string.
Or accidentally omits the '}' in Clark notation. The way xml-types is now, it cannot be used in an environment where code is not allowed to introduce any additional risk of crashes. That is quite common in commercial development. John Millikin wrote:
If you are concerned that a developer may cause exceptions by writing incorrect code, it would be better to use the Name constructor directly.
The only way to ensure that the IsString will not be used would be to remove the instance entirely from xml-types. In GHC there is no way to prevent an instance from being imported when you import any part of a module. But that would be a shame - I have been using xml-types extensively, and I don't think I have used the Name constructor directly even once. It's just so much neater to use the IsString instance. If you don't like my suggestion of what fromString should do when Clark notation fails to parse, that's OK, do something else. As long as it doesn't crash. Let me put it another way. The IsString class was introduced mainly for ByteString and Text; it's a way for other string implementations to hook into Haskell's built-in special syntax for string literals. I think your Name type does qualify though - it really is just a kind of string, with special support for XML namespaces. But people would be really, really surprised if their program crashed at runtime (possibly for a customer) just because of certain characters they included in a string literal. It is very important for any implementation of the fromString method to be total. Thanks, Yitz