Enumerated Type - Algebraic Data Type in Functional Programming

Algebraic Data Type in Functional Programming

In functional programming languages in the ML lineage (e.g., SML, OCaml and Haskell), an algebraic data type with only nullary constructors can be used to implement an enumerated type. For example (in the syntax of SML signatures):

datatype cardsuit = Clubs | Diamonds | Hearts | Spades type card = { suit: cardsuit; value: int } val hand : card list val trump : cardsuit

In these languages the small-integer representation is completely hidden from the programmer, if indeed such a representation is employed by the implementation. However, Haskell has the Enum type class which a type can derive or implement to get a mapping between the type and Int.

Read more about this topic:  Enumerated Type

Famous quotes containing the words algebraic, data, type, functional and/or programming:

    I have no scheme about it,—no designs on men at all; and, if I had, my mode would be to tempt them with the fruit, and not with the manure. To what end do I lead a simple life at all, pray? That I may teach others to simplify their lives?—and so all our lives be simplified merely, like an algebraic formula? Or not, rather, that I may make use of the ground I have cleared, to live more worthily and profitably?
    Henry David Thoreau (1817–1862)

    Mental health data from the 1950’s on middle-aged women showed them to be a particularly distressed group, vulnerable to depression and feelings of uselessness. This isn’t surprising. If society tells you that your main role is to be attractive to men and you are getting crow’s feet, and to be a mother to children and yours are leaving home, no wonder you are distressed.
    Grace Baruch (20th century)

    The Republican form of government is the highest form of government; but because of this it requires the highest type of human nature—a type nowhere at present existing.
    Herbert Spencer (1820–1903)

    Stay-at-home mothers, . . . their self-esteem constantly assaulted, . . . are ever more fervently concerned that their offspring turn out better so they won’t have to stoop to say “I told you so.” Working mothers, . . . their self-esteem corroded by guilt, . . . are praying their kids turn out functional so they can stop being defensive and apologetic and instead assert “See? I did do it all.”
    Melinda M. Marshall (20th century)

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)