I am trying to learn to use the xmlgen library, but when I tried the example from http://factisresearch.blogspot.in/2011/05/xmlgen-feature-rich-and-high.html I get a compile error.
Here is the code:
import Text.XML.Generator
import Data.ByteString.Lazy as BSL
import Prelude as P
genXml' :: Xml Doc
genXml' =
let people = [("Stefan", "32"), ("Judith", "4")]
in doc defaultDocInfo $
xelem "people" $
xelems $ P.map (\(name, age) -> xelem "person" (xattr "age" age <#> xtext name)) people
outputXml :: IO ()
outputXml = BSL.putStr (xrender genXml')
The compiler errors:
$ ghc --make prog.hs
[1 of 1] Compiling Main ( prog.hs, prog.o )
prog.hs:13:25:
No instance for (XmlOutput ByteString)
arising from a use of `xrender'
Possible fix:
add an instance declaration for (XmlOutput ByteString)
In the first argument of `BSL.putStr', namely `(xrender genXml')'
In the expression: BSL.putStr (xrender genXml')
In an equation for `outputXml':
outputXml = BSL.putStr (xrender genXml')
The compiler seems to be deducing that “xrender genXML'” needs to be of type “XmlOutput ByteString” and there is an instance of this in the xmlgen library. So please help me with understanding what this error means, and how it can be fixed.
If it helps, I am using the Haskell Platform in Ubuntu 12.10, ghc 7.4.2 and the xmlgen 0.4.0.3
No, the compiler deduces (from the use of
BSL.putStr) thatxrender genXML'needs to be of typeData.ByteString.Lazy.ByteString.Since the type of
xrenderisa necessary condition to be able to instantiate
twithData.ByteString.Lazy.ByteStringis anXmlOutputinstance for lazyByteStrings.Since there is such an instance exported from
Text.XML.Generator, the only cause for the error message that I see is that yourimports the module from a different version of the
bytestringpackage than thexmlgenlibrary was built against.Can you check that with
ghc-pkg describe xmlgen, which lists thebytestringversion it was built against among the dependencies, andghc-pkg list bytestringto check whichbytestringversions you have installed?