[Haskell-cafe] Re: A Question of Restriction
Ahn, Ki Yung
kyagrd at gmail.com
Mon Jul 27 01:28:03 EDT 2009
Brian Troutwine wrote:
> Hello all.
> I would like to define a data type that is the super-set of several
> types and then each of the proper subset types. For example:
> data Foo = One | Two | Three | Four
> data Odd = One | Three
> data Even = Two | Four
> This, of course, does not work. It seems that such a thing should
> possible to express entirely in the type system, but I cannot think of
> how. Would someone be so kind as to explain how this sort of thing can
> be accomplished?
You might want to look at Johan Nordlander's O'Haskell. It's a dialect
of Haskell with such subtyping, designed and implemented while ago.
Recently there was a proposal (but not an implementation yet) of
subtyping data types in general with recursion and including GADTs
http://portal.acm.org/citation.cfm?id=1411286.1411297 (I want to work on
this again some time later again). But neither of these work is not
implemented as an extension feature in major Haskell implementations
like GHC or Hugs. I want to push this work further some time later on.
FYI, there exist a functional language which you can express this kind
of idea though. For example, in OCaml, you can use polymorphic variants.
More information about the Haskell-Cafe