[Haskell-cafe] partial inheritance

Patrick Browne patrick.browne at dit.ie
Tue Jul 19 01:09:38 CEST 2011


On 18/07/2011 19:14, Jerzy Karczmarczuk wrote:
> That's why I suggested how you might do that: for some datatypes, say
> the Emperors, you specify some special flying method (e.g. dummy or
> bombing), or you don't specify it at all. And the Emperors won't fly.

-- Here is my attempt
data Emperor = Emperor
data Robin = Robin

class Bird a where
   fly :: a -> a -> a
   walk :: a -> a -> a

instance Bird Robin where
  fly x y = y
  walk x y = x

instance Bird Emperor where
-- No fly method
   walk x y = y

class (Bird a) => Penguin a where
-- I do not think that I can override the walk method in the sub-class
-- must be done in instance of Penguin

instance Penguin Emperor where
-- How can I override the walk method in the instance Penguin?
-- walk x y = x


Regards,
Pat

This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie



More information about the Haskell-Cafe mailing list