[web-devel] xml-types IsString instance for Name causes crashes

Michael Snoyman michael at snoyman.com
Sat Jun 11 20:01:59 CEST 2011


On Fri, Jun 10, 2011 at 9:40 PM, John Millikin <jmillikin at gmail.com> wrote:
> On Fri, Jun 10, 2011 at 07:20, Simon Meier <iridcode at gmail.com> wrote:
>> Note that the OverloadedStringLiterals together with the 'IsString'
>> instances gives you more than just a nice syntactic abbreviation: the
>> defined string literals are also lifted out of their context and
>> defined as CAFs. Therefore, you can share the conversion from String
>> to <your-type> during the whole run of a program. We exploit that in
>> blaze-html to do escaping and UTF-8 encoding only once. Hence, in some
>> contexts the IsString instances are necessary.
>
> I'm afraid I don't understand this; could you explain the difference
> between these two definitions? Specifically, why would the
> OverloadedStrings version be more efficient?
>
> -------------------------------------------------------
> foo :: Name
> foo = Name "foo" (Just "urn:bar") Nothing
> -------------------------------------------------------
>
> -------------------------------------------------------
> {-# LANGUAGE OverloadedStrings #-}
> foo :: Name
> foo = "{urn:bar}foo"
> -------------------------------------------------------

Warning: IANAS[1]. I think these two *would* be identical, the
difference would be if you don't declare foo at the top level like
this, but instead use it inline twice. In such a case, the
OverloadedStrings version would be CAFed, while the direct Name
constructor would like the "foo" and "urn:bar" Text values be CAFed
but not the Name value itself.

Michael

[1] I am not a Simon.
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>



More information about the web-devel mailing list