composite-xml: RecXML Type

[ composite, data, library, mit, xml ] [ Propose Tags ]

RecXML type


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies 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) [details]
License MIT
Copyright 2021 Daniel Firth
Author Daniel Firth
Maintainer dan.firth@homotopic.tech
Category Composite, Data, XML
Source repo head: git clone https://gitlab.homotopic.tech/haskell/composite-xml
Uploaded by locallycompact at 2022-07-16T22:03:04Z
Distributions NixOS:0.1.0.0
Downloads 70 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-07-17 [all 1 reports]

Readme for composite-xml-0.1.0.0

[back to package description]

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>