하스켈과 Java/Scala/C# 코드 간의 데이터 교환 솔루션을 찾고 있습니다. 현재 XML 사용에 대해 생각하고 있습니다. 이상적으로는 Haskell 데이터 유형에서 XML 스키마를 생성하고 싶습니다. 첫 번째 시도는 HaXml 1.22.2, DrIFT 2.2.2였습니다. GHC 7.0.3의 모든 것.HaXml 및 DrIFT를 GHC 7.0.3에서 작동시키는 방법은 무엇입니까?
이import Data.List (isPrefixOf)
import Text.XML.HaXml.XmlContent
import Text.XML.HaXml.Types
import Text.XML.HaXml.Pretty (document)
data MyType = A | B String deriving (Eq, Show)
{-! derive : XmlContent !-} -- this line is for DrIFT
이 파일에서, 드리프트 생산 :
{- Generated by DrIFT (Automatic class derivations for Haskell) -}
{-# LINE 1 "ts.hs" #-}
import Data.List (isPrefixOf)
import Text.XML.HaXml.XmlContent
import Text.XML.HaXml.Types
import Text.XML.HaXml.Pretty (document)
data MyType = A | B String deriving (Eq, Show)
{-! derive : XmlContent !-} -- this line is for DrIFT
{-* Generated by DrIFT : Look, but Don't Touch. *-}
instance HTypeable MyType where
toHType v =
Defined "MyType" [] [Constr "A" [] [],Constr "B" [] [toHType aa]]
where
(B aa) = v
instance XmlContent MyType where
parseContents = do
{ [email protected](Elem t _ _) <- elementWith (flip isPrefixOf) ["B","A"]
; case t of
_ | "B" `isPrefixOf` t -> interior e $ fmap B parseContents
| "A" `isPrefixOf` t -> interior e $ return A
}
toContents [email protected] =
[mkElemC (showConstr 0 (toHType v)) []]
toContents [email protected](B aa) =
[mkElemC (showConstr 1 (toHType v)) (toContents aa)]
-- Imported from other files :-
GHC이 코드를 컴파일 오류 메시지가 생성됩니다이 문제와
19:32:
Couldn't match expected type `[Char]' with actual type `QName'
In the second argument of `isPrefixOf', namely `t'
In the expression: "B" `isPrefixOf` t
In a stmt of a pattern guard for
a case alternative:
"B" `isPrefixOf` t
인가는 다음 코드가있다 금형이나 뭔가 잘못하고 있는거야? 이 문제를 해결하는 방법? 주위 HaXml의 이전 버전에 대한 Hackage 설명서
게시 된 코드 조각은 HaXml> = 1.4 –
@ KacperBak : Yep에 대해 의도 된 XmlContent를 사용합니다. 그래도 조사해 보면 1.4 변경 사항이 여기에서 문제가되지 않음을 알 수 있습니다. 이 변화는 훨씬 나중에 일어났습니다. 내 업데이트 답변을 참조하십시오. – hammar
답변 해 주셔서 감사합니다. 지금은 HaXml 1.20.2를 사용하고 모든 것이 예상대로 작동합니다. –