Headline

Dealing with large bananas in Haskell

Characteristics

Large bananas are put to work as a means of generic programming so that operations for cutting or totaling salaries are implemented concisely. Only problem-specific aspects need to be specified. The overall data traversal is provided the generalized folds and suitably predefined fold algebras.

Illustration

See the concept of large bananas for an illustration that actually involves the present contribution.

Architecture

There are these modules:

  • {-| A data model for the 101companies System -}
module Company.Data where -- | A company consists of name and top-level departments data Company = Company Name [Department] deriving (Eq, Read, Show) -- | A department consists of name, manager, sub-departments, and employees data Department = Department Name Manager [Department] [Employee] deriving (Eq, Read, Show) -- | An employee consists of name, address, and salary data Employee = Employee Name Address Salary deriving (Eq, Show, Read) -- | Managers as employees type Manager = Employee -- | Names of companies, departments, and employees type Name = String -- | Addresses as strings type Address = String -- | Salaries as floats type Salary = Float
: a data model for Feature:Hierarchical company
  • module Company.Algebra where
import Company.Data import Data.Monoid -- An algebra type for companies data CompanyAlgebra c d e = CompanyAlgebra { atCompany :: Name -> [d] -> c, atDepartment :: Name -> e -> [d] -> [e] -> d, atEmployee :: Name -> Address -> Salary -> e } -- A family of fold functions for companies and constituents foldCompany :: CompanyAlgebra c d e -> Company -> c foldCompany f (Company n ds) = atCompany f n ds' where ds' = map (foldDepartment f) ds foldDepartment :: CompanyAlgebra c d e -> Department -> d foldDepartment f (Department n m ds es) = atDepartment f n m' ds' es' where m' = foldEmployee f m ds' = map (foldDepartment f) ds es' = map (foldEmployee f) es foldEmployee :: CompanyAlgebra c d e -> Employee -> e foldEmployee f (Employee n w s) = atEmployee f n w s -- An algebra for deep identity mapCompany :: CompanyAlgebra Company Department Employee mapCompany = CompanyAlgebra { atCompany = Company, atDepartment = Department, atEmployee = Employee } -- An algebra for deep mconcat of monoid mconcatCompany :: Monoid m => CompanyAlgebra m m m mconcatCompany = CompanyAlgebra { atCompany = \n ds -> mconcat ds, atDepartment = \n m ds es -> mappend m (mappend (mconcat ds) (mconcat es)), atEmployee = \n w s -> mempty }
: support for large bananas
  • Fragment not found
    : a sample company
  • Fragment not found
    : the implementation of Feature:Total
  • Fragment not found
    : the implementation of Feature:Cut
  • Fragment not found
    : the implementation of Feature:Depth
  • Fragment not found
    : Tests

Usage

See Contribution:haskellComposition.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    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.