Contribution:
haskellEngineer
Headline
Basic software engineering for Haskell
Characteristics
The contribution demonstrates basic means of modularization (using Haskell's native module system), code organization (using where clauses for local scope), packaging (using Technology:Cabal), documentation (using Technology:Haddock), and unit testing (using Technology:HUnit). Other than that, only basic language constructs are exercised and a very limited feature set of the system:Company is implemented. The contribution is indeed more of a showcase for a pattern for modularization, code organization, packaging, documentation, and unit testing.
Illustration
Modular organization
The contribution consists of the modules as listed in following file:
name: haskellEngineer version: 0.1.0.0 synopsis: Basic software engineering for Haskell homepage: http://101companies.org/wiki/Contribution:haskellEngineer build-type: Simple cabal-version: >=1.9.2 library exposed-modules: Main Company.Data Company.Sample Company.Total Company.Cut build-depends: base >=4.4 && < 5.0, HUnit hs-source-dirs: src test-suite basic-tests main-is: Main.hs build-depends: base, HUnit hs-source-dirs: src type: exitcode-stdio-1.0
The modules implement features as follows:
- Company/Data.hs: Feature:Flat company.
- Company/Sample.hs: A sample company.
- Company/Total.hs: Feature:Total.
- Company/Cut.hs: Feature:Cut.
- Main.hs: Unit tests for demonstration.
{-| The operation of totaling all salaries of all employees in a company -}
module Company.Total where
import Company.Data
-- | Total all salaries in a company
total :: Company -> Float
total = sum . salaries
where
-- Extract all salaries in a company
salaries :: Company -> [Salary]
salaries (_, es) = getSalaries es
where
-- Extract all salaries of lists of employees
getSalaries :: [Employee] -> [Salary]
getSalaries [] = []
getSalaries (e:es) = getSalary e : getSalaries es
where
-- Extract the salary from an employee
getSalary :: Employee -> Salary
getSalary (_, _, s) = s
Please note how "where clauses" are used to organize the declarations in such a way that it is expressed what function is a helper function to what other function. The declaration of such local scope also implies that the helper functions do not feed into the interface of the module.
Haddock comments
Technology:Haddock comments are used to enable documentation generation. Consider again the module shown above. Haddock comments are used for the functions total and salaries but not for the remaining functions, as they are not exported and thus, they do not need to be covered by the generated documentation.
External dependencies
The contribution has the following dependencies; see again the .cabal file:
build-depends: base >=4.4 && < 5.0, HUnit
These packages serve the following purposes:
- base: This is the Haskell base package; a range of versions is permitted.
- HUnit: This is the package for Technology:HUnit; its version is not explicitly constrained.
HUnit testcases
The contribution is tested by the following test cases:
tests =
TestList [
TestLabel "total" totalTest,
TestLabel "cut" cutTest,
TestLabel "serialization" serializationTest
]
For instance, the test case for serialization looks as follows:
serializationTest = sampleCompany ~=? read (show sampleCompany)
Relationships
- The present contribution is an "engineered" variation on Contribution:haskellStarter. That is, modularization, packaging, documentation, and unit testing was applied.
- Several other contributions derive from the present contribution more or less directly by demonstrating additional language or technology capabilities or implementing additional features of the system:Company.
Architecture
Modules to feature mapping:
- Company.Data: Feature:Flat company
- Company.Sample: A sample company
- Company.Total: Feature:Total
- Company.Cut: Feature:Cut
- Main: Unit tests for demonstration
Usage
See https://github.com/101companies/101haskell/blob/master/README.md
Backlinks
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.