Headline

Generic programming in Language:Javascript with SYB

Motivation

This implementation shows generic programming in Language:Javascript using SYB style. The data model relies on (recursive) data composition alone. Generic Programming simplifies the traversal over nested data. Functions for total and cut are implemented as generic functions, they contain type specific cases for employees to extract salaries. This library is a port of SYB, in JS this implementation's mapping functions are easily possible due to the simple object structure in Javascript.

Illustration

function cutOne(e) {
    if(e.salary != null) {
        return {
            salary: e.salary/2,
            name: e.name
        };
    }
    else {
        throw new Error("fail");
    }
}
 
cut = everywhere(mkT(cutOne))
cut company = cut(company);
console.log(cut company)

This implementation of total takes the salary of every employee and folds them by adding.

Relationships

Usage

Use node.js to run the example, you can embedd it to an html file too.

$ node syb.js
12345
6172.5


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.