Mark's suggestion for declaring the selector functions
within the datatype already exists in the language OPAL
(developed at TU Berlin). Besides selectors, you also get the
test predicates there.
Example: the declaration
DATA list == empty
:: (first:char, rest: list)
introduces a type list, constructors empty and ::,
selector functions first and rest, and also test predicates
empty? and ::? .
Concerning Mark's comment that
MJ> o Datatype definitions are already rather complicated. In one
MJ> concise notation, they allow us to specify:
MJ> - a new type constructor,
MJ> - a family of new value constructors, and
MJ> - (implicitly, and often neglected) a means of pattern
MJ> matching against values of the new type.
I should add that a datatype definition does even more:
it also solves a recursive type equation (involving a coproduct type)
and it abstracts type variables from the declaration.
One could separate these concepts, although the lack of explicit
type variable abstraction would only be apparent if Haskell had
parameterised modules.
Stefan Kahrs