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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to