[GHC] #14292: Coercing between constraints of newtypes
GHC
ghc-devs at haskell.org
Thu Sep 28 06:55:27 UTC 2017
#14292: Coercing between constraints of newtypes
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
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 AntC):
Replying to [comment:5 AntC]:
> If the module has `IncoherentInstances`, do both those instances get
accepted even without the pragmas? (Or perhaps a more devious scenario
where one of the instances is imported.)
>
Yes, here we go:
{{{
{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving,
FlexibleInstances,
IncoherentInstances #-}
main = print $ MkN (7 :: Int) + MkN 5
newtype N a = MkN a deriving (Show)
instance Num a => Num (N a) where
MkN x + MkN y = MkN (x - y)
deriving instance Num (N Int)
}}}
Without `IncoherentInstances` the `MkN 7 + MkN 5` is rejected: overlapping
instances [good! that's what I want].
With `IncoherentInstances`, this is accepted and prints `12`. If I switch
round the instance decls such that the hand-crafted one is for `Num (N
Int)` and the derived is for `Num (N a)`, this prints `2`.
Ugh!
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14292#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list