[Haskell-cafe] ANN: text 0.5, a major revision of the Unicode text library

Jeremy Shaw jeremy at n-heptane.com
Fri Oct 9 11:33:28 EDT 2009


Sweet!

What are the chances of seeing a, instance Data Text, some day? text  
would be a great type to use with Happstack, because it is far more  
memory efficient than String. But it is difficult to do that with out  
a instance of Data.

For the time being, I have been hacking it with:

instance Data Text where
     toConstr x = mkStringConstr textType (Text.unpack x)
     gunfold _k z c = case constrRep c of
                       (StringConstr x) -> z (Text.pack x)
                       _ -> error "gunfold for Data.Text"
     dataTypeOf _ = textType

But, packing and unpacking the Text is obviously not that cool..

For what it's worth, ByteString is normally exported abstract, and  
just uses, deriving Data. Perhaps we can do the same for text? (I  
believe there are a number of other examples of types in the  
'standard' libraries which are exported abstract, but have Data  
instances...)

- jeremy


More information about the Haskell-Cafe mailing list