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

Brian Hulley brianh at metamilk.com
Sat Jan 6 06:51:35 EST 2007


Bulat Ziganshin wrote:
> 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:
[example snipped]

Hello Bulat,

Thanks for the workaround, which solves the need to copy and paste method 
bodies though not the problem of having to write out instance decls for a 
potentially large chain of classes leading to the subclass of interest. Part 
of the motivation for proposing that a superclass method default could be 
redefined in a subclass (or a particular instance) is that it would allow 
some refactorings of the class hierarchy without affecting code that just 
uses the subclass - in particular it would allow existing code using Monad 
to compile unchanged even when Monad moved down to Functor => Applicative => 
Monad because return and >>= are enough to get completely defined instances 
for Functor and Applicative.

Best regards, Brian.
-- 
http://www.metamilk.com 



More information about the Haskell-Cafe mailing list