Contribution:
haskellHxt
Headline
In-memory XML processing in Language:Haskell with Technology:HXT
Motivation
The implementation demonstrates XML processing in Language:Haskell with Technology:HXT's combinator library. Operations for totaling and cutting salaries are accordingly composed from combinators for XML queries and transformations. The concept of arrows is demonstrated by the implementation as HXT's combinator library essentially relies on arrows.
Illustration
In the following we will demonstrate the construction of an arrow for Feature:Total and how one can run this arrow in IO.
Total
We define a query for totaling all company salaries:
total :: ArrowXml a => a XmlTree Float
total = listA (deep $ hasName "salary"
>>>
getChildren
>>>
getText)
>>>
arr (sum.(map read))
In line 2 we query all salary nodes by using
deep $ hasName "salary" :: ArrowXml a => a XmlTree XmlTree
XmlTree
XmlTree
deep
getChildren >>> getText
>>>
ArrowXml a => a XmlTree String
We then use Control.Arrow.ArrowLists listA
ArrowXml a => a XmlTree [String]
In line 7 the result of this arrow is passed to the lifted version of
(sum.(map read)) :: (Read c, Num c) => [String] -> c
ArrowXml a => a [String] Float
The overall emerging arrow, giving us the total salary, is of type
ArrowXml a => a XmlTree Float
Running an arrow
When we combinate the arrow for reading a sample company from a XML file with the totaling arrow we get:
readDocument [] "sampleCompany.xml" >>> total
We use
runX :: IOSArrow XmlTree c -> IO [c]
[ttl] <- runX ( readDocument [] "sampleCompany.xml"
>>> total )
ttl
Architecture
this!!Total.hs provides the arrow for totaling salaries as described in the illustration section. this!!Cut.hs contains a transformation arrow for cutting salaries. this!!Main.hs collects test scenarios for totaling and cutting XML data provided by this!!sampleCompany.xml
Usage
- this!!Main.hs has to be loaded into GHCi.
- The function has to be applied.
main
- The output should be equal to the content of the file this!!baseline.
There are no revisions for this page.
User contributions
User edits
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.
Syntax for editing wiki
For you are available next options:will make text bold.
will make text italic.
will make text underlined.
will make text striked.
will allow you to paste code headline into the page.
will allow you to link into the page.
will allow you to paste code with syntax highlight into the page. You will need to define used programming language.
will allow you to paste image into the page.
is list with bullets.
is list with numbers.
will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.
will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.
will allow your to insert code snippets from @worker.