[Haskell-cafe] partial inheritance

Yves Parès limestrael at gmail.com
Tue Jul 19 01:13:14 CEST 2011


Oh, I got it: You want to have:

class Bird b where

class Penguin p where

instance (Penguin b) => Bird b where
   fly = -- fly method for penguins

2011/7/19 Patrick Browne <patrick.browne at dit.ie>

> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110719/372429ff/attachment.htm>


More information about the Haskell-Cafe mailing list