[Haskell-cafe] partial inheritance

Yves Parès limestrael at gmail.com
Tue Jul 19 10:43:17 CEST 2011


> I haven't followed the thread carefully but why does the bird have to be a
penguin?

A bird doesn't have to be a penguin :

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

Says that every Penguin is a Bird.
But thinking back about it, there is a problem when trying to define the
method walk, because:

class Penguin p where
   walkPenguin :: ....

instance (Penguin b) => Bird b where
    fly = .....
    walk = walkPenguin

is kind of awful, because walk has to be duplicated. So, not the best way to
go...


2011/7/19 Maciej Marcin Piechotka <uzytkownik2 at gmail.com>

> On Tue, 2011-07-19 at 01:13 +0200, Yves Parès wrote:
> > 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
> >
>
> I haven't followed the thread carefully but why does the bird have to be
> a penguin?
>
> ----------
>
> As a side note - I agree with Christopher Done that the answer is that
> you shouldn't require for bird to fly.
>
> Regards
>
> _______________________________________________
> 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/a9668e2d/attachment.htm>


More information about the Haskell-Cafe mailing list