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

siki gabor at karamaan.com
Mon Apr 27 17:00:18 EDT 2009


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

data Blah = Blah
data Bar = Bar

instance A Blah
instance B Bar 

let blah = Blah
    bar = Bar

foo blah -- should print out 5
foo bar  -- should print out 7

Basically, I have a bunch of instances that have a common functionality but
I'd like to be able to group those instances and give each group a different
default implementation of that functionality. It's so easy to do this in
Java, for example, but I have no idea how to do it in Haskell. The above
example will not compile, btw.

Thanks a lot
-- 
View this message in context: http://www.nabble.com/Can-subclass-override-its-super-class%27-default-implementation-of-a-function--tp23264975p23264975.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list