Subtyping
Mansour Al-Mutairi
almutaim@hotmail.com
Sat, 18 Aug 2001 17:29:29
Hi,
I am a newbie but I think that what you are proposing can be simulated in
haskell. It is like subclassing in OOP. You can create a new type that is an
extension of the older one. Unlike OOP overloading, you will need to create
a new function that can work on the new type.
>data SomeObject = SomeInt Int | SomeString String | _
will become:
data SomeObject = SomeInt Int | SomeString String
>...later...
>
>data SomeObject |= SomeReal Double
will become:
data SomeObject2 = SO SomeObject | SomeReal Double
>same :: SomeObject -> SomeObject -> Bool
>same (SomeInt a) (SomeInt b) = a == b
>same (SomeString a) (SomeString b) = a == b
>same _ _ = False
>
>...later...
>
>same (SomeReal a) (SomeReal b) = a == b
will become:
same :: SomeObject -> SomeObject -> Bool
same (SomeInt a) (SomeInt b) = a == b
same (SomeString a) (SomeString b) = a == b
...later...
same2 :: SomeObject2 -> SomeObject2 -> Bool
same2 (SomeReal a) (SomeReal b) = a == b
same2 x y = same x y
tell me if I am wrong.
thanks.
Mansour Al-Mutairi :)
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp