[Haskell-cafe] class default method proposal

Stefan O'Rear stefanor at cox.net
Tue Dec 11 10:07:20 EST 2007


On Tue, Dec 11, 2007 at 02:20:52PM +0000, Duncan Coutts wrote:
> I'd just like to float an idea that's related to the Class Alias
> proposal[1] but is perhaps somewhat simpler.
> 
> We all know that Functor should have been a superclass of Monad, and
> indeed we now know that Applicative should be too. Making such a change
> would break lots of things however so the change does not happen.
> 
> However in this case the Monad operations can be used to implement the
> Functor and Applicative class methods. So it would be nice if we could
> get them for free if the author did not choose to write the Functor and
> Applicative instances.
> 
> So my suggestion is that we let classes declare default implementations
> of methods from super-classes.
> 
> class Functor m => Monad m where
>   {- the ordinary bits -}
> 
>   fmap f m    = m >>= return . f
> 
> So if there already is a Functor instance for m then the default
> implementation of fmap is not used.
> 
> 
> Does this proposal have any unintended consequences? I'm not sure.
> Please discuss :-)
> 
> Duncan
> 
> [1] http://repetae.net/recent/out/classalias.html

This is almost exactly the
http://haskell.org/haskellwiki/Class_system_extension_proposal; that
page has some discussion of implementation issues.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20071211/bdba81da/attachment.bin


More information about the Haskell-Cafe mailing list