[Haskell-cafe] Type extensions

Henning Thielemann lemming at henning-thielemann.de
Wed Jun 1 10:54:28 EDT 2005


On Wed, 1 Jun 2005, Thomas Davie wrote:

> Hi,
>    I was wondering if I hat missed something and it was possible to
> do this within the Haskell type system or not...
>
> Essentially I would like some sort of inderritance property for
> Haskell types, I often find myself wanting to for example extend a
> tree with black/white colouring, or later extend the tree with some
> sort of ID, etc.
>
> So I would eno up with three data types
>
> data MyTree = Branch MyTree MyTree | Leaf
>
> type BwTag = Bool
> data MyBwTree = Branch BwTag MyBwTree MyBwTree | Node BwTag

What about

data MyTree a = Branch a (MyTree a) (MyTree a) | Node a

and the types
 MyTree ()
 MyTree Bool
 MyTree (Bool, Int)
 ?



More information about the Haskell-Cafe mailing list