Headline

A simple implementation in F# for the Technology:.NET Framework

Characteristics

The contribution demonstrates basic style of functional programming in F#. Persons, Employees, Departments and Companies are represented via record types. Pure functions are implemented in pipelining style to realize totaling and cutting salaries.

Illustration

The company model uses records to data composition:

Basic types for strings and floats are used to represent names, addresses and salaries. More advanced arrays are used to represent a collection of the recently named records (Employee, Department)

The Department record is structured as follows

type Department = {
         mutable Name : string;
         mutable Manager : Employee;
         mutable Employees : Employee[];
         mutable SubUnits : Department[];
        }

Feature:Total and Feature:Cut are implemented by families of functions on the company types. We only show the family for totaling salaries here which uses pipelining style.

-- Total all salaries in a company
-- totalComp:: Company -> Decimal
let totalComp (comp:Company) = 
    List.fold (fun (acc) (elem:Department) -> acc + totalDept(elem)) 0M (List.ofSeq comp.Departments)

    
-- Total all salaries in a department
-- totalDept:: Department -> Decimal
let rec totalDept (dept:Department) =
    dept.Manager.Salary
    |> fun t -> List.fold (fun (acc) (elem:Department) -> acc + totalDept(elem)) t (List.ofSeq dept.SubUnits)
    |> fun t -> List.fold (fun (acc) (elem:Employee) -> acc + elem.Salary) t (List.ofSeq dept.Employees)

Architecture

The contribution consit of four modules: "CompanyModels.fs" which contains the definition of the used classes (including the total / cut function); "CompanyBuilder.fs" which creates a sample instance of a company; "Program.fs" which basically creates a sample company through "buildCompany" of "CompanyBuilder.fs" and executes total and cut printing the results (simple testing); "Test.fs" which contains a more professional NUnit Test scenario.

Metadata


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.

    10 most similar pages:

    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.