@hackage composite-xml0.1.0.0
RecXML Type
Categories
License
MIT
Maintainer
dan.firth@homotopic.tech
Links
Versions
- 0.1.0.0 Sat, 16 Jul 2022
Installation
Dependencies (6)
- base >=4.7 && <5
- composite-base >=0.7.0.0 && <0.9
- containers
- text >=1.0 && <2.1
- vinyl >=0.13.0 && <0.15
- xml-conduit >=1.9 && <2.0 Show all…
Dependents (0)
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>