Description
RecXML Type.
Description
RecXML type
README.md
composite-xml
A simple xml parser/printer type using composite records. RecXML is defined like
data RecXML :: Symbol -> [Type] -> [Type] -> Type where
RNode :: Rec Maybe xs -> [Field ys] -> RecXML s xs ys
An RNode
is typed indexed by it's node name, an index of attributes it may contain, and list of child node types of which it may contain any number or multiplicity. The child nodes will typically also be RecXMLs, but this is not enforced.
withLensesAndProxies
[d|
type A = "a" :-> Text
type B = "b" :-> Int
type C = "c" :-> Bool
type D = "d" :-> Text
type E = "e" :-> Int
|]
type Child1 = RecXML "Child1" '[C] '[]
type Child2 = RecXML "Child2" '[D, E] '[]
type Root = RecXML "Root" '[A, B] '[Child1, Child2]
child1 :: Child1
child1 = RNode (Just True :^: RNil) []
child2 :: Child2
child2 = RNode (Just "bar" :^: Just 7 :^: RNil) []
child2b :: Child2
child2b = RNode (Just "quux" :^: Just 8 :^: RNil) []
root :: Root
root = RNode (Just "foo" :^: Just 5 :^: RNil) $ [field child1, field child2, field child2b]
corresponds to the xml
<Root a="foo" b="5">
<Child1 c="true"></Child1>
<Child2 d="bar" e="7"></Child2>
<Child2 d="quux" e="8"></Child2>
</Root>