[Haskell-cafe] Can subclass override its super-class' default
implementation of a function?
david48
dav.vire+haskell at gmail.com
Tue Apr 28 07:05:53 EDT 2009
On Mon, Apr 27, 2009 at 11:00 PM, siki <gabor at karamaan.com> 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
I probably don't understand the question properly, but I don't see why
you would need another class here.
Why not :
module Main where
class A a where
foo :: a -> Double
foo _ = 5.0
data Blah = Blah
data Bar = Bar
instance A Blah
instance A Bar where
foo _ = 7.0
blah = Blah
bar = Bar
main = do
print $ foo blah -- prints 5.0
print $ foo bar -- prints 7.0
More information about the Haskell-Cafe
mailing list