[Haskell-beginners] Hexpat: GeneriXMLString instances not recognized?

Aleksandar Dimitrov aleks.dimitrov at googlemail.com
Sun Oct 24 18:08:37 EDT 2010


Hi list,

I'm trying to use Hexpat to efficiently SAX-parse an XML document (of  
quite some size.) So I figured it'd be a good idea to use Data.Text as the  
string type for my parsed XML data. It seems Hexpat's sax-parse function  
only accepts files in ByteString format, which is fair enough, but here's  
the really weird thing: the following line yields a compilation error!

> import Text.XML.Expat.SAX
> import qualified Data.Text as T
> import qualified Data.ByteString.Lazy as L
>main = do f <- L.readFile someFile
>           let x = parse defaultParseOptions f :: [SAXEvent T.Text T.Text]
> ...

The error:
     No instance for (GenericXMLString T.Text)
       arising from a use of `parse' at Polyparse.hs:15:12-38
     Possible fix:
       add an instance declaration for (GenericXMLString T.Text)
     In the expression:
           parse defaultParseOptions f :: [SAXEvent T.Text T.Text]

That's mighty strange, seeing as there is an instance for GenericXMLString  
Data.Text.Text in hexpat's source code (indeed, it's one of its advertised  
features!) Here is the documentation (as well as the source:
http://hackage.haskell.org/packages/archive/hexpat/0.19.4/doc/html/Text-XML-Expat-SAX.html#t:GenericXMLString

I went ahead and tried copying the instance declaration from the source to  
my own code. I noticed it didn't compile, since the type signature of  
peekByteStringLen (called from the Text instance declaration for  
GenericXMLString) clashed with the function's use of  
ByteString.Internal.ByteString (the type signature specified whatever  
ByteString Data.ByteString exports.)

Now my question is twofold: what am I overlooking? Why didn't it compile?  
I can install and compile the very same code easily via cabal, but it  
doesn't compile inside my program. Is there some magic at work that I  
missed? Secondly, why doesn't ghc recognize the instance declaration  
GenericXMLString Data.Text.Text, when it really should? (It does recognize  
the declaration for String!)

Thanks for any pointers!
Aleks


More information about the Beginners mailing list