Re: Overlapping and incoherent instances

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@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 :(

| >>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. I see your point. Though you could just grep for OVERLAP! I suppose that -XOverlappingInstances could mean "silently honour OVERLAPPABLE/OVERLAPPING pragmas", while lacking it would mean "honour OVERLAPPABLE/OVERLAPPING pragmas, but emit noisy warnings" or even "don't honour them and warn". But that is different to the behaviour today, so we'd need a new LANGUAGE pragma. Perhaps -XHonourOverlappingInstances or something. My sense is that the extra faff is not worth it. | >>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? It's a user decision. GHC allows - OVERLAPPABLE at the instance that is being overlapped, or - OVERLAPPING at the instance that is doing the overlapping, or - both Another possible choice would be to require both. One or t'other wouldn't do. But the current choice (with the LANGUAGE pragmas -XOverlappingInstances) is the either/or choice, and I had no user pressure to change that. There *is* user pressure for the either/or semantics, so that you can *later* add an un-anticipated OVERLAPPING instance. | > {-# 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. It's pretty clearly stated in the manual, but I'd be delighted to add a paragraph or two, or an example, if you can draft something and say where a good place for it would be (ie where you'd have looked). Thanks Simon
participants (2)
-
Ben Millwood
-
Simon Peyton Jones