[Haskell-cafe] Can subclass override its super-class' default implementation of a function?

Martijn van Steenbergen martijn at van.steenbergen.nl
Mon Apr 27 17:15:55 EDT 2009


siki wrote:
> I'm not sure if this is possible at all. I'd like to do something like this:
> 
> class A a where
>     foo :: a -> Double
>     
>     foo a = 5.0
> 
> 
> class (A a) => B a where
>     foo a = 7.0

This is currently not possible in Haskell. It's been proposed, though:

http://haskell.org/haskellwiki/Class_system_extension_proposal

If you have an actual example we might be able to come up with a 
different way of modelling it so that it does what you want, though.

Martijn.



More information about the Haskell-Cafe mailing list