[GHC] #10991: Don't permit type variables in the context unless they are in the type

#10991: Don't permit type variables in the context unless they are in the type -------------------------------------+------------------------------------- Reporter: bernalex | Owner: bernalex Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: (Type checker) | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC accepts Unknown/Multiple | invalid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHC accepts the following: {{{ f :: Eq a => b -> b f b = b }}} This is not valid Haskell 2010[0], so we should not permit it. [0] «The context cx must only contain type variables referenced in t», https://www.haskell.org/report/node/2010/haskellch4.html#x10-660004.1.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10991 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10991: Don't permit type variables in the context unless they are in the type -------------------------------------+------------------------------------- Reporter: bernalex | Owner: bernalex Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Which version of GHC are you using that this is accepted? ghc-7.10.2 reports: {{{ Test.hs:3:6: Could not deduce (Eq a0) from the context (Eq a) bound by the type signature for f :: Eq a => b -> b at Test.hs:3:6-19 The type variable ‘a0’ is ambiguous In the ambiguity check for the type signature for ‘f’: f :: forall b a. Eq a => b -> b To defer the ambiguity check to use sites, enable AllowAmbiguousTypes In the type signature for ‘f’: f :: Eq a => b -> b }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10991#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10991: Don't permit type variables in the context unless they are in the type -------------------------------------+------------------------------------- Reporter: bernalex | Owner: bernalex Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bernalex): Interesting. It seems to only accept the ill-typed code in GHCi. {{{ λ let f :: Eq a => b -> b; f b = b λ :t f f :: b -> b }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10991#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10991: Don't permit type variables in the context unless they are in the type -------------------------------------+------------------------------------- Reporter: bernalex | Owner: bernalex Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler (Type | Version: checker) | Resolution: invalid | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC accepts | Unknown/Multiple invalid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => invalid Comment: GHCi sets [https://downloads.haskell.org/~ghc/7.10.2/docs/html/users_guide /interactive-evaluation.html#extended-default-rules `-XExtendedDefaultRules`], which is the reason why your code is accepted. The following snippet is [https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.... valid Haskell], and thus always accepted, even when first running `:set -XNoExtendedDefaultRules` (note that because of #10857, running `ghci -XNoExtendedDefaultRules` doesn't work currently): {{{ let h :: Num a => b -> b; h b = b }}} The following is always rejected (only Show, Eq, and Ord are treated specially with `-XExtendedDefaultRules`): {{{ let g :: Read a => b -> b; g b = b }}} I don't think there is a bug here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10991#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC