HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Default method implementation

Categories: Style

It's always a design question, whether to provide default implementions of methods of Type classes and how to design them.

Here are some suggestions:

E.g. if you have a Monad constraint, but no Functor constraint, then use liftM instead of fmap.
E.g. the default methods of the class providing divMod, div, and mod should implement the defaults, where divMod calls div and mod and vice versa.
Do not try to implement mod by repeated subtraction or so.
E.g. "instances must implement divMod or (div and mod)"


See also

http://www.haskell.org/pipermail/haskell-cafe/2006-November/019329.html

Retrieved from "http://haskell.org/haskellwiki/Default_method_implementation"

This page has been accessed 801 times. This page was last modified 16:04, 7 June 2007. Recent content is available under a simple permissive license.