Keywords and syntaxLanguage reference
Summary
In recent versions of GHC there is a notion of roles (see GHC Guide).
Types that have the same representation (e.g. a type and its newtype) can be converted between each other with coerce or with -XGeneralizedNewtypeDeriving. Roles exist to constrain ways in which types can be converted. For instance, this definition will disallow converting Set a to Set b even if b is a newtype of a:
type role Set nominalThe reason it's not safe to convert a Set is that the set will have a different structure depending on the Ord instance of what's stored inside, and instances can be different for newtypes even if the representations are the same.
There are three roles:
nominal: types must be completely identical after type family reductionrepresentational: types must have the same representationphantom: the type can be disregarded