문제

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?
도움이 되었습니까?

해결책

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

다른 팁

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).
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top