[GHC] #15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint`
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs {-# Language DataKinds, TypeInType, TypeFamilies #-} import Data.Kind newtype I a = I a type C = Constraint type family UnitC :: Constraint where UnitC = () instance UnitC => Functor I where fmap = undefined }}} this works fine, but if I try to use the constraint synonym `C` (`UnitC :: C where`) fails with "Instance head is not headed by a class" which has '''no''' Google hits outside of the [https://hackage.haskell.org/package/ghc-8.4.1/docs/src/TcValidity.html#check... compiler] {{{ $ ghci -ignore-dot-ghci hs/249.hs GHCi, version 8.5.20180128: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hs/249.hs, interpreted ) hs/249.hs:13:10: error: • Instance head is not headed by a class • In the instance declaration for ‘Functor I’ | 13 | instance UnitC => Functor I where | ^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. Prelude> }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 simonpj): Can you give the code that fails? In general, in an instance {{{ instance ... => C t1 t2 where ... }}} `C` must be a class; at least that's what the error message is complaining about. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 monoidal): The failing code is obtained by replacing `Constraint` by `C`: {{{ {-# Language DataKinds, TypeInType, TypeFamilies #-} import Data.Kind newtype I a = I a type C = Constraint type family UnitC :: C where UnitC = () instance UnitC => Functor I where fmap = undefined }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 Iceland_jack): Yes sorry, I should have included the failing code. Here is a version without type families {{{#!hs {-# Language DataKinds, TypeInType, ConstraintKinds #-} import Data.Kind data A :: Type type C = Constraint type UnitC = (() :: C) instance UnitC => Eq A where (==) = undefined }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 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 Simon Peyton Jones <simonpj@…>): In [changeset:"c5d31df70b16dc346b5860077c8bbe585ddb7a78/ghc" c5d31df7/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="c5d31df70b16dc346b5860077c8bbe585ddb7a78" Treat isConstraintKind more consistently It turned out that we were not being consistent about our use of isConstraintKind. It's delicate, because the typechecker treats Constraint and Type as /distinct/, whereas they are the /same/ in the rest of the compiler (Trac #11715). And had it wrong, which led to Trac #15412. This patch does the following: * Rename isConstraintKind to tcIsConstraintKind returnsConstraintKind to tcReturnsConstraintKind to emphasise that they use the 'tcView' view of types. * Move these functions, and some related ones (tcIsLiftedTypeKind), from Kind.hs, to group together in Type.hs, alongside isPredTy. It feels very unsatisfactory that these 'tcX' functions live in Type, but it happens because isPredTy is called later in the compiler too. But it's a consequence of the 'Constraint vs Type' dilemma. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | testsuite/tests/typecheck/should_compile/T15412 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * testcase: => testsuite/tests/typecheck/should_compile/T15412 Comment: Wow, that was bad! Thank you for reporting; now fixed. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | testsuite/tests/typecheck/should_compile/T15412 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged in 6a7cb80648253ebcc84be5f11e2cc78eae085aa8. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#15412: "Instance head is not headed by a class" when `Constraint` replaced with `type C = Constraint` -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | testsuite/tests/typecheck/should_compile/T15412 Blocked By: | Blocking: Related Tickets: #15583 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * related: => #15583 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15412#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC