gpt4 book ai didi

Haskell HXT Pickle

转载 作者:行者123 更新时间:2023-12-02 18:59:20 25 4
gpt4 key购买 nike

我刚刚使用 XML 的“hxt”包编写了一个简单的程序:

module Main(main,pickle)    where

import qualified Text.XML.HXT.Arrow.Pickle as HXT.Arrow.Pickle
import qualified Text.XML.HXT.Arrow.Pickle.Xml as HXT.Arrow.Pickle.Xml
import qualified Text.XML.HXT.Core as HXT.Core
import qualified System.Environment

newtype Subject = MkSubject Int deriving (Read, Show)

instance HXT.Arrow.Pickle.XmlPickler Subject where
xpickle = xpSubject

xpSubject :: HXT.Arrow.Pickle.Xml.PU Subject
xpSubject = HXT.Arrow.Pickle.xpElem "Subject" . HXT.Arrow.Pickle.xpWrap (
MkSubject,
\(MkSubject x) -> x
) . HXT.Arrow.Pickle.xpAttr "Topic" $ HXT.Arrow.Pickle.xpPrim

pickle :: String -> IO ()
pickle srcFilePath = HXT.Core.runX (
HXT.Core.xunpickleDocument xpSubject [
HXT.Core.withValidate HXT.Core.yes,
HXT.Core.withTrace maxBound,
HXT.Core.withRemoveWS HXT.Core.yes,
HXT.Core.withPreserveComment HXT.Core.yes
] srcFilePath
) >> return ()

main :: IO ()
main = pickle =<< fmap head System.Environment.getArgs

OpenSuSE-11.4 上编译此代码,使用 ghc-7.4.1 可以正常工作:

$ ghc Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...

在示例 XML 文件上运行会导致无限循环:

$ ./Main subject.xml 
-- (1) readDocument: start processing document "subject.xml"
-- (2) setDefaultBaseURI: new default base URI is "file:///home/al/Documents/Software/Haskell/Test/"
-- (2) setBaseURI: new base URI is "file:///home/al/Documents/Software/Haskell/Test/"
-- (2) setBaseURI: new base URI is "file:///home/al/Documents/Software/Haskell/Test/subject.xml"
-- (2) getURIContents: reading "file:///home/al/Documents/Software/Haskell/Test/subject.xml"
-- (2) read file "/home/al/Documents/Software/Haskell/Test/subject.xml" (strict input = False)
-- (2) decodeDocument: encoding is "ISO-8859-15"
-- (1) getXmlContents: content read and decoded for "file:///home/al/Documents/Software/Haskell/Test/subject.xml"
-- (1) getXmlContents'


content of: subject.xml
=======================

---XTag "/"
| "version"="1.0"
| "encoding"="ISO-8859-15"
| "transfer-MimeType"="text/xml"
| "transfer-Status"="200"
| "transfer-Message"="OK"
| "transfer-URI"="file:///home/al/Documents/Software/Haskell/Test/subject.xml"
| "source"="subject.xml"
| "transfer-Encoding"="ISO-8859-15"
|
+---XText "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n\n<!-- An example of the specification in XML, of the problem-parameters -->\n\n<Subject Topic=\"test\"/>\n\n<!-- End -->\n\n"


-- (1) readDocument: "subject.xml" (mime type: "text/xml" ) will be processed
-- (2) checkUndefinedEntityRefs: looking for undefined entity refs
-- (2) checkUndefinedEntityRefs: looking for undefined entity refs done
-- (1) readDocument: "subject.xml" processed
<!-- An example of the specification in XML, of the problem-parameters -->
<Subject Topic="test"/>
<!-- End -->


content of: subject.xml
=======================

---XTag "/"
| "version"="1.0"
| "encoding"="ISO-8859-15"
| "transfer-MimeType"="text/xml"
| "transfer-Status"="200"
| "transfer-Message"="OK"
| "transfer-URI"="file:///home/al/Documents/Software/Haskell/Test/subject.xml"
| "source"="subject.xml"
| "transfer-Encoding"="ISO-8859-15"
|
+---XCmt " An example of the specification in XML, of the problem-parameters "
|
+---XTag "Subject"
| | "Topic"="test"
|
+---XCmt " End "



fatal error: document unpickling failed
xpPrim: reading string "test" failed
context: Main: <<loop>>

当然,这是我第一次使用“hxt”,我怀疑这是一个根本性的错误......但打包的示例代码表现出相同的行为:

$ cd ~/.cabal/packages/hackage.haskell.org/hxt/9.2.2/hxt-9.2.2/examples/arrows/pickle
$ make
ghc -Wall -O2 --make -o pickleTest PickleTest.hs
[1 of 1] Compiling Main ( PickleTest.hs, PickleTest.o )
Linking pickleTest ...
make: *** No rule to make target `PickleTestWithNamespaces.hs', needed by `pickleTestWithNamespaces'. Stop.

$ ./pickleTest
### Error in: 0:pickle/unpickle tests with example programs:0:0
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:0:1
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:0:2
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:0:3
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:0:4
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:0:5
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:0
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:1
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:2
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:3
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:4
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:1:5
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:0
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:1
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:2
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:3
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:4
<<loop>>
### Error in: 0:pickle/unpickle tests with example programs:2:5
<<loop>>
Cases: 18 Tried: 18 Errors: 18 Failures: 0
Counts {cases = 18, tried = 18, errors = 18, failures = 0}

我怀疑这是软件包的一些不匹配:

$ ghc-pkg list
/usr/local/lib/ghc-7.4.1/package.conf.d
Cabal-1.14.0
array-0.4.0.0
base-4.5.0.0
bin-package-db-0.0.0.0
binary-0.5.1.0
bytestring-0.9.2.1
containers-0.4.2.1
deepseq-1.3.0.0
directory-1.1.0.2
extensible-exceptions-0.1.1.4
filepath-1.3.0.0
ghc-7.4.1
ghc-prim-0.2.0.0
haskell2010-1.1.0.1
haskell98-2.0.0.1
hoopl-3.8.7.3
hpc-0.5.1.1
integer-gmp-0.4.0.0
old-locale-1.0.0.4
old-time-1.1.0.0
pretty-1.1.1.0
process-1.1.0.1
rts-1.0
template-haskell-2.7.0.0
time-1.4
unix-2.5.1.0
/home/al/.ghc/x86_64-linux-7.4.1/package.conf.d
HTTP-4000.2.3
HUnit-1.2.4.2
QuickCheck-2.4.2
cpphs-1.13.3
dotgen-0.4.1
hashable-1.1.2.3
haskell-lexer-1.0
haskell-src-exts-1.13.0
hlint-1.8.28
hscolour-1.19
html-1.0.1.2
hxt-9.2.2
hxt-charproperties-9.1.1
hxt-regex-xmlschema-9.0.4
hxt-unicode-9.0.2
mtl-2.1
network-2.3.0.13
parallel-3.2.0.2
parsec-3.1.2
primes-0.2.1.0
random-1.0.1.1
regex-base-0.93.2
regex-posix-0.95.1
syb-0.3.6
text-0.11.2.0
transformers-0.3.0.0
uniplate-1.6.7
unordered-containers-0.2.1.0
xhtml-3000.2.0.5
zlib-0.5.3.3

感谢您提前提供的任何帮助。

最佳答案

尝试在没有优化/规则的情况下安装 hxt,看看错误是否仍然发生。

如果没有,您就遇到了这个错误:http://hackage.haskell.org/trac/ghc/ticket/2722

关于Haskell HXT Pickle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10515003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com