[Haskell-cafe] could we get a Data instance for Data.Text.Text?
Jeremy Shaw
jeremy at n-heptane.com
Fri Jan 22 17:24:19 EST 2010
Hello,
Would it be possible to get a Data instance for Data.Text.Text? This would
allow us to create a Serialize instance of Text for use with happstack --
which would be extremely useful.
We (at seereason) are currently using this patch:
http://src.seereason.com/haskell-text-debian/debian/patches/add_Data_instance.patch
which basically adds:
+textType = mkStringType "Data.Text"
+
+instance Data Text where
+ toConstr x = mkStringConstr textType (unpack x)
+ gunfold _k z c = case constrRep c of
+ (CharConstr x) -> z (pack [x])
+ _ -> error "gunfold for Data.Text"
+ dataTypeOf _ = textType
+
This particular implementation avoids exposing the internals of the
Data.Text type by casting it to a String in toConstr and gunfold. That is
similar to how Data is implemented for some numeric types. However, the
space usage of casting in Float to a Double is far less than casting a Text
to a String, so maybe that is not a good idea?
Alternatively, Data.ByteString just does 'deriving Data'. However,
bytestring also exports Data.ByteString.Internal, wheres Data.Text.Internal
is not exported.
Any thoughts? I would like to get this handled upstream so that all
happstack users can benefit from it.
- jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100122/8b8673d8/attachment.html
More information about the Haskell-Cafe
mailing list