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

Simon Peyton-Jones simonpj at microsoft.com
Fri Apr 29 03:54:26 EDT 2005

| 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)
| Nothing
| 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

As Ben says, this is altogether a bigger deal.  You can imagine two main

1.  NEither simply "macro-includes" the constructors of Either in
NEither, but they are different constructors.  So Either.Left and
NEither.Left would be different, and incompatible constructors.  This is
simple, but clunky; for example, now you'd need to use a qualified name
to disambiguate which you meant, whenever you used Left.

2.  Use sub-typing, so that a value (Left x) is *both* in type Either
and in type NEither.  This opens a very large and complicated design
space, as Ben mentioned.  


More information about the Haskell-Cafe mailing list