[Haskell-cafe] Redefining superclass default methods in a subclass

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Jan 5 08:18:48 EST 2007

Hello Brian,

Thursday, January 4, 2007, 10:00:05 PM, you wrote:

> deeper, the programmer is burdened more and more by the need to
> cut-and-paste method definitions between instances because Haskell doesn't 
> allow a superclass (or ancestor class) method default to be redefined in a 
> subclass.

i've runned into this problem with Streams library. finally i've decided to
wrote bodies of such methods outside of class:

getLineBody :: (CharStream h) =>  h -> IO String
getLineBody h = do
   c <- getChar

instance LineStream File where
  getLine = getLineBody

instance LineStream MemBuf where
  getLine = getLineBody

where File and MemBuf, of course, are CharStream instances

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list