Contribution:
haskellTree
Headline
Data processing in Language:Haskell with functors and foldable types
Characteristics
The data structure of a company is converted to a leaf-labeled rose tree which preserves the tree-like shape of the input but otherwise only represents the salary values at the leaves. Thus, names and other properties of departments and employees are not exposed. Such trees are declared as a functor and a foldable type. A bidirectional transformation is then employed to model a salary cut. That is, the company structure is converted to the leaf-labeled tree, then, in turn, to a list, on which to perform salary cut so that finally the modified salaries are integrated back into the company structure.
Illustration
Consider the following sample company:
sampleCompany :: Company
sampleCompany =
Company
"Acme Corporation"
[
Department "Research"
(Employee "Craig" "Redmond" 123456)
[]
[
(Employee "Erik" "Utrecht" 12345),
(Employee "Ralf" "Koblenz" 1234)
],
Department "Development"
(Employee "Ray" "Redmond" 234567)
[
Department "Dev1"
(Employee "Klaus" "Boston" 23456)
[
Department "Dev1.1"
(Employee "Karl" "Riga" 2345)
[]
[(Employee "Joe" "Wifi City" 2344)]
]
[]
]
[]
]
When converted to a leaf-labeled rose tree, the sample company looks as follows:
sampleTree :: LLTree Float
sampleTree =
Fork [
Fork [
Leaf 123456.0,
Leaf 12345.0,
Leaf 1234.0],
Fork [
Leaf 234567.0,
Fork [
Leaf 23456.0,
Fork [
Leaf 2345.0,
Leaf 2344.0]]]]
Here is the corresponding conversion function; it is a get function in the terminology of bidirectional transformation:
get :: Company -> LLTree Float
get (Company n ds) = Fork (map getD ds)
where
getD :: Department -> LLTree Float
getD (Department n m ds es) = Fork ( [getE m]
++ map getD ds
++ map getE es )
where
getE :: Employee -> LLTree Float
getE (Employee s) = Leaf s
Because LLTree is a foldable type, it is trivial to further convert the tree to a plain list. Accordingly, salary cut can be expressed at the level of lists. The modified salaries are then put back into the tree with a put function, which we skip here for brevity.
cut :: Company -> Company
cut c = put fs' c
where
fs = toList (get c)
fs' = map (/2) fs
Architecture
There are these modules:
A data model for Feature:Hierarchical company
A sample company
The implementation of Feature:Total
The implementation of Feature:Cut
A bidirectional transformation
Leaf-labeled rose trees
Tests
The types of
Usage
See https://github.com/101companies/101haskell/blob/master/README.md.
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.