[web-devel] xml-types IsString instance for Name causes crashes
gale at sefer.org
Thu Jun 9 10:27:01 CEST 2011
>> Since the whole idea of xml-types is for it to be a
>> unifying standard, I'd like to see it usable in that kind
>> of environment, too.
> It is usable in such an environment -- simply do not
> use the IsString instance.
Once you have the Name type rather than just Text -
which is useful for people needing namespaces -
the IsString instance is important to keep code from
becoming really awkward.
Perhaps the real problem here is including Clark
notation in the IsString instance. Clark notation is
very nice, but it doesn't really belong in the IsString
instance. Clark notation could be a function, or a
quasi-quoter. Perhaps the client library should be
allowed to decide.
But if it is included in the IsString instance, it
absolutely cannot raise an asynchronous exception.
That is a serious bug.
>> In addition, I have already pointed out that semantically
>> it doesn't make sense for a fromString implementation
>> to return _|_. And it is easy to make a small change
>> to the current implementation to avoid that.
>> So let me turn the question around. Is there a compelling
>> reason why, in some use case, the fromString must
>> return _|_, rather than returning some text that will allow
>> the application to handle the situation itself?
> The string "foo}bar" is invalid; it must *never* be converted to a
> Name. Doing so would cause silent, unpredictable failures which cannot
> be tested for.
'}' `elem` name would do the trick nicely.
The Name type already produces invalid XML. A client library
that wants to avoid invalid names must already check for them.
If a typo in Clark notation were another way to create invalid
XML that wouldn't change anything.
But if that really bothers you, let's discuss the many other
options for introducing Clark notation other than in the IsString
> IsString does not support reporting parse errors;
Right, and it shouldn't. IsString is just a way of giving a different
string type, like ByteString or Text, to Haskell's string literal syntax.
There is no parsing to do beyond what the compiler already does.
Any IsString instance should just take the contents of the string
literal and incorporate it directly into the string type.
There is no language I've ever heard of where you can cause a
program to crash at *runtime* because of the particular characters
you include in a string literal in your source code. Please don't make
Haskell the first. That would be very ironic.
> if you're very concerned about it, I could add a flag like
> "NoIsString" which disables that particular instance. You could enable
> it in your build scripts.
I wouldn't use that flag. I need and use the IsString instance.
The instance must be defined in the module that defines the type.
More information about the web-devel