Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADT names. What is `Left a`, and then what is `a`, in Haskell?

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?
like image 614
user2023370 Avatar asked Nov 01 '11 16:11

user2023370


2 Answers

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).
like image 91
Sumudu Fernando Avatar answered Nov 02 '22 02:11

Sumudu Fernando


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

like image 28
stonemetal Avatar answered Nov 02 '22 03:11

stonemetal