declaring minimal complete instance definition

Twan van Laarhoven twanvl at gmail.com
Tue May 28 20:00:29 CEST 2013


On 23/05/13 22:20, Shachaf Ben-Kiki wrote:
> On Thu, May 23, 2013 at 4:17 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:
>> 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
>>
>
> See my proposal along these lines from a few months ago to implement
> this as a pragma in GHC:
>
> http://hackage.haskell.org/trac/ghc/ticket/7633
>
>      Shachaf

I have made an implementation, the patch is attached to that ticket.

Twan




More information about the Libraries mailing list