Incorrect number of parameters in "role" errors
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.