
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

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

On 1 Jun 2005, at 15:54, Henning Thielemann wrote:
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) ?
That's exactly what I would normally do, but my data type is in a library and is not parameterised. Tom Davie

On Wed, 1 Jun 2005, Thomas Davie wrote:
On 1 Jun 2005, at 15:54, Henning Thielemann wrote:
What about
data MyTree a = Branch a (MyTree a) (MyTree a) | Node a
and the types MyTree () MyTree Bool MyTree (Bool, Int) ?
That's exactly what I would normally do, but my data type is in a library and is not parameterised.
Then it is the wrong library. :-)

G'day all.
Quoting Thomas Davie
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.
Have you had a look at these? http://haskell.org/hawiki?IndirectComposite http://haskell.org/hawiki?DecoratingStructures Cheers, Andrew Bromage
participants (3)
-
ajb@spamcop.net
-
Henning Thielemann
-
Thomas Davie