[Haskell-cafe] Type extensions
tom.davie at gmail.com
Wed Jun 1 11:03:11 EDT 2005
On 1 Jun 2005, at 15:54, Henning Thielemann wrote:
> On Wed, 1 Jun 2005, Thomas Davie wrote:
>> 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.
More information about the Haskell-Cafe