[Haskell-cafe] RFE: Extensible algebraic user-defined data types?

Dimitry Golubovsky golubovsky at gmail.com
Thu Apr 28 10:48:05 EDT 2005


Is it possible to have such a feature in the future versions of the
Haskell language?

For example, there is an Either datatype which is Left a| Right b.

Suppose I want to extend this datatype to the one including
possibility of neither Left or Right (i. e. None). Currently I have to
use Maybe Either, so my options are:

Just (Left a)
Just (Right b)

If I could extend the Either datatype I might have (syntax may be
different, this is just an example)

data NEither a b = <Either a b> | None

where datatype in angles is a parent datatype, and all its possible
data constructors are included, and their list is extended with None.

which gave me possibilities: Left a | Right b | None

Probably I wouldn't expect to be able to reuse Nothing here (although
I might want to) because Nothing already has been defined to be of the
type Maybe.

This is just a suggestion, that's why it is posted in the Cafe.

PS Or is there a similar feature in the language already?

Regarding reusing constructor names across several datatypes: is it
possible to qualify them with their enclosing datatype name, like
Maybe.Nothing where there is a name conflict? Then I might reuse
Nothing in my hypothetical data type, and it would be NEither.Nothing
if conflicting with Maybe.Nothing

PPS I may be missing something again, as always ;)

Dimitry Golubovsky

Anywhere on the Web

More information about the Haskell-Cafe mailing list