[GHC] #8994: type checker could not deduce ambiguous instances

#8994: type checker could not deduce ambiguous instances ------------------------------------+------------------------------------- Reporter: divip | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- GHC halts with a type error on the following program. If I comment out a seemingly unrelated part, it compiles though. Tested with GHC 7.8.2 {{{#!haskell {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-} class (F a ~ Int) => -- if this line is commented out, the program compiles C a where type F a f :: b -> a run :: (forall a. C a => a) -> () run _ = () x = run (f 0) -- type error: Could not deduce (Num b0) arising from the literal ‘0’ from the context (C a) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8994 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8994: type checker could not deduce ambiguous instances -------------------------------------+------------------------------------ Reporter: divip | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by divip): GHC 7.6.3 compiles is. GHC 7.8.1 does not compile it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8994#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8994: type checker could not deduce ambiguous instances -------------------------------------+------------------------------------ Reporter: divip | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * status: new => closed * resolution: => invalid Comment: The reason this works in 7.6.3 is because GHC defaults the ambiguous type variable 'b', which arises from the call to `f` in `run (f 0)`. It sets `b := Integer`, and all is well. But 7.8 is more cautious about defaulting. Consider: {{{ class (c ~ Int) => C a c where type F a f :: b -> a run :: (forall a c. C a c => a) -> () }}} In this form there is another way to make the program typecheck, by setting `b := c`. So GHC's defaulting rule (which is necessarily ad-hoc, and always was), is a bit more conservative in 7.8, and declines to set `b := Integer` in case you really intended `b := c`. So you need a type signature. This would not be a hard design choice to liberalise. But I erred on the side of being conservative. Generally speaking it's better not to rely on defaulting, anyway. Just use that type signature! I'll close as invalid, but I'm open to user pressure! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8994#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8994: type checker could not deduce ambiguous instances -------------------------------------+------------------------------------ Reporter: divip | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by divip): Thanks for the explanation. About my user experience: The example code was extracted from a bigger program. I did incremental refactoring steps on my program. In one step I introduced a new associated type which was independent of the rest of the program (like `type F a` above which should not interfere with defaulting), and my program stopped to compile. So I was almost sure this is a compiler bug. Improving on this behaviour is not very important for me, it was just unexpected during programming. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8994#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8994: type checker could not deduce ambiguous instances -------------------------------------+------------------------------------ Reporter: divip | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by divip): Thanks, wrote a reply below before I noticed there is a `reply` button. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8994#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC