Question

If I have a Haskell ADT such as:

data Foo
 = A Int Double
 | B Bool [Integer]
 | C (Maybe String) Float

the A, B, and C are referred to as data constructors; and sometimes as value constructors. But what is the correct name for:

  1. a "row/alternative": e.g. B Bool [Integer]; and
  2. a "field/element" of a "row/alternative": e.g. the Double in A, or the [Integer] in B?
Was it helpful?

Solution

data Foo = A Int Double
     ^^ Type Constructor "data Foo"
           ^ value Constructor "A"
             ^^ Component "Int" and "Double"

A | B is usually referred to as alternatives or cases. Sorry for the crappy diagram.

Source: Real World Haskell ch3

OTHER TIPS

Reading Section 4.2 from the Haskell98 Report ( http://www.haskell.org/onlinereport/decls.html ):

  1. This isn't spelled out explicitly, but B Bool [Integer] is probably most correctly called a "constructor declaration" (for the constructor called B)
  2. Things like the Double in A are called field declarations (though simply calling it a field should be OK too).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top