[GHC] #10905: Incorrect number of parameters in "role" errors
GHC
ghc-devs at haskell.org
Mon Sep 21 16:27:17 UTC 2015
#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
More information about the ghc-tickets
mailing list