[GHC] #15135: Overlapping typeclass instance selection depends on the optimisation level
GHC
ghc-devs at haskell.org
Wed May 9 16:25:01 UTC 2018
#15135: Overlapping typeclass instance selection depends on the optimisation level
-------------------------------------+-------------------------------------
Reporter: nicuveo | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.6.1
Component: Compiler | Version: 8.4.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
You are on thin ice here. In `getInt`:
{{{
getInt :: A a => a -> Int
getInt x = fromMaybe 0 $ someValue x
}}}
we have a "wanted" constraint `A a`. How can we solve it? In two ways:
* From the instance
* From the `A a =>` given to `getInt`.
GHC chooses to solve it from the instance. But then you later overlap the
instance, so that decision was arguably wrong. But the same thing would
happen if you tried to infer a type for `getInt`:
{{{
getInt x = fromMaybe 0 $ someValue x
}}}
Again, GHC will use the instance and infer
{{{
getInt :: a -> Int
}}}
If you want to signal to GHC that the instance might be overlapped, use
`{-# OVERLAPPABLE #-}`; and then you'll always get 42.
I think it's arguable that an instance should only be overlappable if it
says `{-# OVERLAPPABLE #-}`. But that's not our current spec.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15135#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list