我正在尝试学习使用xmlgen库,但是当我尝试来自http://factisresearch.blogspot.in/2011/05/xmlgen-feature-rich-and-high.html的示例时,出现编译错误。
这是代码:
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')
编译器错误:
$ 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')
编译器似乎推断“xrender genXML”需要是“XmlOutput ByteString”类型,并且在 xmlgen 库中有一个这样的实例。因此,请帮助我了解此错误的含义以及如何修复它。
如果有帮助,我在 Ubuntu 12.10、ghc 7.4.2 和 xmlgen 0.4.0.3 中使用 Haskell 平台