[GHC] #13061: Incorrect constraints given single flexible undecidable instance

#13061: Incorrect constraints given single flexible undecidable instance -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 (Type checker) | Keywords: Constraint, | Operating System: Unknown/Multiple UndecidableInstances, | FlexibleInstances | Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool If we add: {{{#!hs instance A Int where f = id }}} Then f will have the type A a => a -> a -> Bool. A function of type A a => ... will always be rejected unless Eq is also included -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by JCarr: @@ -16,1 +16,2 @@ - If we add: {{{#!hs + If we add: + {{{#!hs New description: If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool If we add: {{{#!hs instance A Int where f = id }}} Then f will have the type A a => a -> a -> Bool. A function of type A a => ... will always be rejected unless Eq is also included -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by JCarr: @@ -14,1 +14,3 @@ - f will have type Eq a => a -> a -> Bool + f will have type Eq a => a -> a -> Bool. + A function of type A a => ... will always be rejected unless Eq is also + included. @@ -21,3 +23,1 @@ - Then f will have the type A a => a -> a -> Bool. - A function of type A a => ... will always be rejected unless Eq is also - included + Then f will have the correct type A a => a -> a -> Bool. New description: If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool. A function of type A a => ... will always be rejected unless Eq is also included. If we add: {{{#!hs instance A Int where f = id }}} Then f will have the correct type A a => a -> a -> Bool. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance. Adding more clarification of inconsistency -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by JCarr): * type: bug => feature request @@ -15,2 +15,10 @@ - A function of type A a => ... will always be rejected unless Eq is also - included. + Consider the functions + {{{#!hs + g :: A a => a -> a + g = f + h :: A a => a -> a + h = let f' = f in f + i = f' where + f' = f + }}} + h and i will both fail to typecheck. @@ -24,0 +32,4 @@ + + This has been closed previously, but the contrast between g and h above is + worth the reconsideration, as it makes some valid functions not definable + unless an instance is added. New description: If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool. Consider the functions {{{#!hs g :: A a => a -> a g = f h :: A a => a -> a h = let f' = f in f i = f' where f' = f }}} h and i will both fail to typecheck. If we add: {{{#!hs instance A Int where f = id }}} Then f will have the correct type A a => a -> a -> Bool. This has been closed previously, but the contrast between g and h above is worth the reconsideration, as it makes some valid functions not definable unless an instance is added. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance. -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by JCarr: @@ -17,1 +17,1 @@ - g :: A a => a -> a + g, h, i :: A a => a -> a @@ -19,1 +19,0 @@ - h :: A a => a -> a New description: If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool. Consider the functions {{{#!hs g, h, i :: A a => a -> a g = f h = let f' = f in f i = f' where f' = f }}} h and i will both fail to typecheck. If we add: {{{#!hs instance A Int where f = id }}} Then f will have the correct type A a => a -> a -> Bool. This has been closed previously, but the contrast between g and h above is worth the reconsideration, as it makes some valid functions not definable unless an instance is added. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance. -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by JCarr): * type: feature request => bug -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance. -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by JCarr: @@ -31,4 +31,0 @@ - - This has been closed previously, but the contrast between g and h above is - worth the reconsideration, as it makes some valid functions not definable - unless an instance is added. New description: If a class has an instance in the form F a => G a in its file, and no other instances, then the functions in G a will have the constraint F a, rather than G a. Example file {{{#!hs {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} class A a where f :: a -> a instance {-# OVERLAPPABLE #-} Eq a => A a where f = id }}} f will have type Eq a => a -> a -> Bool. Consider the functions {{{#!hs g, h, i :: A a => a -> a g = f h = let f' = f in f i = f' where f' = f }}} h and i will both fail to typecheck. If we add: {{{#!hs instance A Int where f = id }}} Then f will have the correct type A a => a -> a -> Bool. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13061: Incorrect constraints given single flexible undecidable instance. -------------------------------------+------------------------------------- Reporter: JCarr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Keywords: Constraint, Resolution: | UndecidableInstances, | FlexibleInstances Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Interesting. This happens because when you bind a variable with `let`/`where`, GHC simplifies the type. In your case, it simplifies `A a => a -> a` to `Eq a => a -> a`, choosing the `Eq a => A a` instance. This is a bit bogus, though, because `Eq a => a -> a` is not actually more general than `A a => a -> a` in the presence of other instances. I'm not sure what to do here, really. I think this may just be an oddity of `FlexibleInstances`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13061#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC