[GHC] #10905: Incorrect number of parameters in "role" errors

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Keywords: roles | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- The following code produces the error: {{{ import Data.Coerce import Data.Functor.Trans.Tagged toTT :: Tagged t [a] -> TaggedT t [] a toTT = coerce }}} {{{ Couldn't match representation of type ‘[a]’ with that of ‘Data.Functor.Identity.Identity [a]’ arising from trying to show that the representations of ‘Tagged t [a]’ and ‘TaggedT t [] a’ are the same Relevant role signatures: type role [] representational type role Data.Functor.Identity.Identity representational type role TaggedT nominal nominal phantom representational nominal The data constructor ‘Data.Functor.Identity.Identity’ of newtype ‘Data.Functor.Identity.Identity’ is not in scope Relevant bindings include toTT :: Tagged t [a] -> TaggedT t [] a (bound at Main.hs:9:1) In the expression: coerce In an equation for ‘toTT’: toTT = coerce }}} First, kudos for correctly identifying the problem: I failed to import the `Identity` constructor. However, it seems that the report for the roles of the `TaggedT` type has too many parameters. It is defined in tagged-transformer [https://hackage.haskell.org/package/tagged-transformer-0.8/docs/Data- Functor-Trans-Tagged.html] as `newtype TaggedT s m b = TagT { untagT :: m b }`, but is listed with 5 roles. I did try to move the definition of `TaggedT/Tagged` into my module so I didn't have to import the library, but when I did the error didn't show up: TaggedT was listed with the expected roles `phantom representational nominal`. As a user, it wasn't clear to me why there are 5 roles listed for a type with 3 parameters, and I didn't know which roles I should be looking at to help me debug the `coerce` error. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): I know what's going on here: GHC is reporting the role of //kind// parameters (which are all nominal). It shouldn't (unless you say `-fprint- explicit-kinds`, I think). Easy to fix. But Simon removed this role-signature-reporting code. From !TcErrors: {{{ -- SLPJ Jun 15: I could not convince myself that these hints were really -- useful. Maybe they are, but I think we need more work to make them -- actually helpful. }}} So the error is therefore absent in HEAD. But I thought those role signatures were helpful, and it sounds like @crockeea does too. So, Simon, care to elaborate on why you removed these? Are there too many signatures reported? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Here's my test case. It produces the bad output in 7.10, but (as noted above) not in HEAD. {{{ {-# LANGUAGE PolyKinds #-} module T10905 where import Data.Coerce import Data.Functor.Identity data TaggedT s m b = TagT { untagT :: m b } foo :: TaggedT () [] Int -> TaggedT () [] (Identity Int) foo = coerce -- test the printing of TaggedT's role signature }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Old description:
The following code produces the error:
{{{ import Data.Coerce import Data.Functor.Trans.Tagged
toTT :: Tagged t [a] -> TaggedT t [] a toTT = coerce }}}
{{{ Couldn't match representation of type ‘[a]’ with that of ‘Data.Functor.Identity.Identity [a]’ arising from trying to show that the representations of ‘Tagged t [a]’ and ‘TaggedT t [] a’ are the same Relevant role signatures: type role [] representational type role Data.Functor.Identity.Identity representational type role TaggedT nominal nominal phantom representational nominal The data constructor ‘Data.Functor.Identity.Identity’ of newtype ‘Data.Functor.Identity.Identity’ is not in scope Relevant bindings include toTT :: Tagged t [a] -> TaggedT t [] a (bound at Main.hs:9:1) In the expression: coerce In an equation for ‘toTT’: toTT = coerce }}}
First, kudos for correctly identifying the problem: I failed to import the `Identity` constructor. However, it seems that the report for the roles of the `TaggedT` type has too many parameters. It is defined in tagged-transformer [https://hackage.haskell.org/package/tagged-transformer-0.8/docs/Data- Functor-Trans-Tagged.html] as `newtype TaggedT s m b = TagT { untagT :: m b }`, but is listed with 5 roles.
I did try to move the definition of `TaggedT/Tagged` into my module so I didn't have to import the library, but when I did the error didn't show up: TaggedT was listed with the expected roles `phantom representational nominal`.
As a user, it wasn't clear to me why there are 5 roles listed for a type with 3 parameters, and I didn't know which roles I should be looking at to help me debug the `coerce` error.
New description: The following code produces the error: {{{ import Data.Coerce import Data.Functor.Trans.Tagged toTT :: Tagged t [a] -> TaggedT t [] a toTT = coerce }}} {{{ Couldn't match representation of type ‘[a]’ with that of ‘Data.Functor.Identity.Identity [a]’ arising from trying to show that the representations of ‘Tagged t [a]’ and ‘TaggedT t [] a’ are the same Relevant role signatures: type role [] representational type role Data.Functor.Identity.Identity representational type role TaggedT nominal nominal phantom representational nominal The data constructor ‘Data.Functor.Identity.Identity’ of newtype ‘Data.Functor.Identity.Identity’ is not in scope Relevant bindings include toTT :: Tagged t [a] -> TaggedT t [] a (bound at Main.hs:9:1) In the expression: coerce In an equation for ‘toTT’: toTT = coerce }}} First, kudos for correctly identifying the problem: I failed to import the `Identity` constructor. However, it seems that the report for the roles of the `TaggedT` type has too many parameters. It is defined in tagged-transformer [https://hackage.haskell.org/package/tagged-transformer-0.8/docs/Data- Functor-Trans-Tagged.html] as `newtype TaggedT s m b = TagT { untagT :: m b }`, but is listed with 5 roles. I did try to move the definition of `TaggedT/Tagged` into my module so I didn't have to import the library, but when I did the error didn't show up: TaggedT was listed with the expected roles `phantom representational nominal`. As a user, it wasn't clear to me why there are 5 roles listed for a type with 3 parameters, and I didn't know which roles I should be looking at to help me debug the `coerce` error. It's also not clear why using the library vs defining the types locally changed the behavior. -- Comment (by crockeea): I agree with your test case, and it appears that 5 roles are printed with both `-fprint-explicit-kinds` and with `-fno-print-explicit-kinds`, which seems odd (or is that merely because of `PolyKinds`?). I suppose it makes sense to print the roles of the kinds if you have `fprint-explicit-kinds` enabled, but in my original test case (without `fprint-explicit-kinds` or `PolyKinds`, the kind roles should probably not be printed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): I don't think my reasoning was any deeper than the comment says. In the example in the Description, the roles are a distraction from the main point: the constructor isn't in scope. They just get in the way, and for most people will be mysterious and confusing. Do we even want to see these role, or perhaps the roles of type constructors we have decomposed on the way to getting this error? To put it another way, can you give an example of where they are useful? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by goldfire): If I say {{{ import Data.Coerce data G a where MkG :: G Int newtype Age = MkAge Int go :: G Age -> G Int go = coerce }}} I get {{{ Couldn't match type ‘Int’ with ‘Age’ arising from trying to show that the representations of ‘G Age’ and ‘G Int’ are the same Relevant role signatures: type role G nominal In the expression: coerce In an equation for ‘go’: go = coerce }}} That role signature looks helpful. Perhaps !TcErrors could be more selective in deciding which signatures to include (though I'm not quite sure how to get this right), but I do think they're good to see. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

I don't think my reasoning was any deeper than the comment says. In the example in the Description, the roles are a distraction from the main
#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: roles Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by crockeea): To me this is a separate issue from the bug I reported. I have no problem with the fact that roles were reported for a missing constructor error. If anything I think the roles *help* in my example. The ticket as reported is really just about when the kind-roles should be printed, as that's the part I found confusing. Replying to [comment:4 simonpj]: point: the constructor isn't in scope. They just get in the way, and for most people will be mysterious and confusing.
Do we even want to see these role, or perhaps the roles of type
constructors we have decomposed on the way to getting this error?
To put it another way, can you give an example of where they are useful?
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10905: Incorrect number of parameters in "role" errors -------------------------------------+------------------------------------- Reporter: crockeea | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: roles Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Incorrect | Test Case: warning at compile-time | ghci/scripts/T16030 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => ghci/scripts/T16030 * status: new => closed * resolution: => fixed Comment: Replying to [comment:6 crockeea]:
The ticket as reported is really just about when the kind-roles should be printed, as that's the part I found confusing.
In that case, this ticket is fixed. The `T16030` test case provides a regression test for this, as it displays: {{{#!hs type role Foo1 phantom }}} When `-fprint-explicit-kinds` is disabled, and displays: {{{#!hs type role Foo1 nominal phantom }}} When `-fprint-explicit-kinds` is enabled. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10905#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC