ADT names. What is `Left a`, and then what is `a`, in Haskell?
-
18-02-2021 - |
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:
- a "row/alternative": e.g.
B Bool [Integer]
; and - a "field/element" of a "row/alternative": e.g. the
Double
inA
, or the[Integer]
inB
?
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.
OTHER TIPS
Reading Section 4.2 from the Haskell98 Report ( http://www.haskell.org/onlinereport/decls.html ):
- This isn't spelled out explicitly, but
B Bool [Integer]
is probably most correctly called a "constructor declaration" (for the constructor calledB
) - Things like the
Double
inA
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