[Haskell-cafe] partial inheritance

Richard O'Keefe ok at cs.otago.ac.nz
Tue Jul 19 05:53:51 CEST 2011


On 19/07/2011, at 11:09 AM, Patrick Browne wrote:
> 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

Note that "no 'fly' method is visibly presented" is
not at all the same thing as "no 'fly' method EXISTS".

From the report:
   "The default class method for v sub i is used if
    no binding for it is given in a particular
    instance declaration (see Section 4.3.2)."
so the absence of a method in 'instance Bird Emperor'
doesn't mean that it doesn't _have_ one, just that it
inherits the default class method.





More information about the Haskell-Cafe mailing list