oops, for the sake of completeness you also need:

textType = mkStringType "Data.Text"

- jeremy

On Oct 9, 2009, at 10:33 AM, Jeremy Shaw wrote:

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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to