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

data MyBwTaggedTree = Branch BwTag Int MyBwTaggedTree MyBwTaggedTree | Node BwTag Int

and several functions to move from one to another. (Or define the most complex and not always use all the attrdbutes). What I would prefer is to be able to spocify something like:

data MyTree = Branch MyTree MyTree | Leaf

type BwTag = Bool
data MyBwTree extends MyTree with BwTag=True

data MyBwTaggedTree extends MyBwTree with Int=0

Specifying that myBwTree is the same as MyTree but with an extra argument on each node, and to generate functions to translate between them that fill in True as a default value for the extra tag.

Is this possible?

Thanks

Tom Davie

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

Reply via email to