Headline

Equivalence of types based on their structure

Illustration

Consider the following declarations in Language:Haskell:

type Point = (Float, Float) -- A Cartesian point
type Rectangle = (Float, Float) -- A rectangle with width and height

Because both types are defined as type synonyms, they are subject to structural typing. Thus, points and rectangles are compatible such that a point can be used whereever a rectangle is expected, and vice versa. This is arguably not intended. We may instead define the types as follows:

data Point = Point Float Float -- A Cartesian point
data Rectangle = Rectangle Float Float -- A rectangle with width and height

While both types are structurally equivalent, as both types declare one data constructor with the exact same types for the constructor components, the types are still different as nominal typing applies for Haskell's algebraic data types.

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.

    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.