
On 2013-05-23 21:56:30 +0200, Henning Thielemann wrote: [...]
Currently, when I forget to implement the two essential Monad methods return' and '>>=' in a Monad instance, I get a warning. However with the mutual implementations of 'join' and '>>=' I do not get a warning but an infinite loop. Similarly, I already had nasty bugs with (a-b) defaulting to (a + negate b) and (negate a) defaulting to (0-a).
As this is a general problem which comes up often with mutually recursive default implementations for typeclass methods, I have been wondering if somebody came up with a solution for that, which allows the compiler to emit warnings or even errors. Often the documentation for a typeclass already specifies the "minimal complete definition", if this could be meta-annotated with some pragma for the compiler to pick up, we could have the compiler help us avoid invalid instance definition. Has some ghc-feature/extension to this effect been discussed in the past? Btw, even the simple 'Eq' and 'Ord' classes have mutually depending default implementations: - Eq: "Minimal complete definition: either '==' or '/='." - Ord: "Minimal complete definition: either 'compare' or '<='. Using 'compare' can be more efficient for complex types." cheers, hvr