[GHC] #9288: Type class overlapping instances check doesn't understand type equality

#9288: Type class overlapping instances check doesn't understand type equality -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type | Version: 7.9 checker) | Operating System: Unknown/Multiple Keywords: | Type of failure: GHC accepts Architecture: Unknown/Multiple | invalid program Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | -------------------------------------+------------------------------------- Here is a sample program which we'd expect to give an overlapping instances error, but does not: {{{ {-# LANGUAGE TypeFamilies, FlexibleInstances #-} module Foo where type family F a :: * type instance F Bool = Int type instance F Int = Bool class C a where instance (F Bool ~ a) => C a where instance C Int where }}} Fortunately, GHC does notice when you actually try to use the instance. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9288 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9288: Type class overlapping instances check doesn't understand type equality ------------------------------------------------+-------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type checker) | Version: 7.9 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts invalid program | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Comment (by aavogt): A simpler example where ghc-7.8.2 doesn't detect overlapping instances until they are used {{{ {-# LANGUAGE FlexibleInstances #-} class C a where c :: a instance C a where c = undefined instance C Int where c = 2 -- ghc doesn't complain about overlapping instances -- unless you uncomment c1 -- c1 = c :: Int c2 = c :: Double }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9288#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9288: Type class overlapping instances check doesn't understand type equality ------------------------------------------------+-------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler (Type checker) | Version: 7.9 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts invalid program | Unknown/Multiple Test Case: | Difficulty: Blocking: | Unknown | Blocked By: | Related Tickets: ------------------------------------------------+-------------------------- Changes (by aavogt): * cc: vogt.adam@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9288#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9288: Type class overlapping instances check doesn't understand type equality -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: closed Priority: low | Milestone: Component: Compiler | Version: 7.9 (Type checker) | Keywords: Resolution: invalid | Operating System: Unknown/Multiple Differential Revisions: | Type of failure: GHC accepts Architecture: | invalid program Unknown/Multiple | Test Case: Difficulty: Unknown | Blocking: Blocked By: | Related Tickets: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => invalid Comment: This is by design. GHC does not report overlapping instances eagerly (at the instance definition site). Rather it reports them lazily (when used). There is good reason for this: {{{ instance C Int a where instance C b Bool where }}} If we reported errors eagerly we'd have to say they overlap. But there is no problem with, say `(C Int Char)`. It's nothing to do with equalities. The user manual does not say this explicitly, so I'll fix that. Thanks for raising it. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9288#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9288: Type class overlapping instances check doesn't understand type equality
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: bug | Status: closed
Priority: low | Milestone:
Component: Compiler | Version: 7.9
(Type checker) | Keywords:
Resolution: invalid | Operating System: Unknown/Multiple
Differential Revisions: | Type of failure: GHC accepts
Architecture: | invalid program
Unknown/Multiple | Test Case:
Difficulty: Unknown | Blocking:
Blocked By: |
Related Tickets: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC