Overlapping and incoherent instances

Ben Millwood haskell at benmachine.co.uk
Sat Aug 2 20:54:57 UTC 2014


On Sat, Aug 02, 2014 at 08:51:57PM +0100, Ben Millwood wrote:
>On Sat, Aug 02, 2014 at 04:27:14PM +0100, Ben Millwood wrote:
>>On Thu, Jul 31, 2014 at 07:20:31AM +0000, Simon Peyton Jones wrote:
>>>My main motivation was to signal the proposed deprecation of the global per-module flag -XoverlappingInstances.  Happily people generally seem fine with this.   It is, after all, precisely what deprecations are for ("the old thing still works for now, but it won't do so for ever, and you should change as soon as is convenient").
>>
>>Here's one concern I have with the deprecation of 
>>-XOverlappingInstances: I don't like overlapping instances, I find 
>>them confusing and weird and prefer to use code that doesn't 
>>include them, because they violate my expectations about how type 
>>classes work. When there is a single LANGUAGE pragma, that's a 
>>simple, easily-checkable signpost of "this code uses techniques 
>>that Ben doesn't understand". When it is all controlled by pragmas 
>>I basically have to check every instance declaration individually.
>>
>>On a largely unrelated note, here's another thing I don't 
>>understand: when is OVERLAPPABLE at one instance declaration 
>>preferable to using only OVERLAPPING at the instance declarations 
>>that overlap it? In the latter model, as long as none of the 
>>instances I write have pragmas, I can be sure none of them overlap. 
>>In the former model, any instance I write for an existing typeclass 
>>might overlap another instance, even if I don't want it to. Do we 
>>have any specific use cases in mind for OVERLAPPABLE?
>>_______________________________________________
>>Libraries mailing list
>>Libraries at haskell.org
>>http://www.haskell.org/mailman/listinfo/libraries
>
>When I originally sent this mail I wasn't subscribed to the GHC 
>lists, so I went and fixed that and am now resending.

Good grief, and then I sent from the wrong address. Sorry for the noise.

>Addendum: I was surprised by the behaviour of overlapping instances 
>when I went and looked closer at it.
>
>    {-# LANGUAGE FlexibleInstances #-}
>    module M where
>    class C a where f :: a -> a
>    instance C a where f x = x
>    instance C Int where f x = x + 1
>
>I suspect many people have the intuition that NoOverlappingInstances 
>should forbid the above, but in fact OverlappingInstances or no only 
>controls instance *resolution*. I imagine you all already knew this 
>but I did not until I carefully reread things.
>
>As someone who dislikes overlapping type class instances, I am 
>finding them harder to avoid than I at first thought :(


More information about the Glasgow-haskell-users mailing list