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)

    This city is neither a jungle nor the moon.... In long shot: a cosmic smudge, a conglomerate of bleeding energies. Close up, it is a fairly legible printed circuit, a transistorized labyrinth of beastly tracks, a data bank for asthmatic voice-prints.
    Susan Sontag (b. 1933)

    The more characteristic American hero in the earlier day, and the more beloved type at all times, was not the hustler but the whittler.
    Mark Sullivan (1874–1952)

    Indigenous to Minnesota, and almost completely ignored by its people, are the stark, unornamented, functional clusters of concrete—Minnesota’s grain elevators. These may be said to express unconsciously all the principles of modernism, being built for use only, with little regard for the tenets of esthetic design.
    —Federal Writers’ Project Of The Wor, U.S. public relief program (1935-1943)

    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)