
#16241: Avoid orphan instances with OVERLAPPABLE (sometimes) -------------------------------------+------------------------------------- Reporter: AntC | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: #15135 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by AntC): Thanks Simon,
Currently the user manual ...
is only talking about compiling within a single module, or at least when all instances are visible from imports in a single module. I.e. compiling module `Main` in the example. Or if you squish all the code into a single module then indeed
you don't need to say "OVERLAPPABLE" for an instance to be overlappable.
But when compiling version 2 of module `Help` * there is only one visible instance of `MyShow` (so the quote from the manual doesn't apply: there's no alternative candidates to eliminate); * its head `[a]` does indeed match the wanted constraint `MyShow [a] =>` from the signature for `showHelp`, so it's the "prime candidate" per the user manual; and yet * the instance is marked `OVERLAPPABLE`, then GHC ''doesn't'' select that instance, contra what the user manual says. * I know it doesn't select that instance, because it doesn't simplify to constraint `MyShow a =>`. * Then in compiling module `Main`, we maintain referential transparency: `showHelp [MkT]` ===> `myshow [MkT]`, which wants `instance MyShow [T]` in preference to `instance MyShow [a]`. * So both calls in `main` produce the same result, viz `"Used more specific instance"`. So I'm disagreeing with your
It's enough to say "OVERLAPPING" in the overlapping instance.
It is enough only providing those overlapping instance(s) are in the same module. If the overlapping instance(s) are in a separate module that's importing the `OVERLAPPABLE` instance, then you must say the imported instance is OVERLAPPABLE.
So you can't deduce anything much from the absence of "OVERLAPPABLE", sadly.
Well, you can deduce you're liable to see "fragile"/"incoherent" behaviour ;-).
If we you could only overlap an explicitly-overlappable instance, we could commit to them more aggressively.
I think you have that back-to-front: this ticket is showing currently GHC does commit aggressively to an eligible instance ''unless'' it's explicitly-overlappable. (And BTW per #15135, with `-O2` GHC commits aggressively anyway and ignores `OVERLAPPABLE`.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16241#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler