Allow role inference on datatype contexts
|Reported by:||goldfire||Owned by:||goldfire|
|Type of failure:||None/Unknown||Test Case:||roles/should_compile/T8958|
|Related Tickets:||Differential Rev(s):|
Currently, role inference on a datatype examines the use of a type parameter in all constructors of that datatype. This, of course, includes any constraint contexts on these datatypes. But, the (stupid) datatype context is not consulted, as there is no need to do so for type safety.
However, by examining the datatype context, we can create a lightweight way of annotating roles, like this:
class Nominal a instance Nominal a type role Nominal nominal -- this is redundant, but here for completeness class Representational a instance Representational a type role Representational representational -- this requires -XIncoherentInstances class Phantom a -- any use of this class is redundant, but here for completeness instance Phantom a type role Phantom phantom data (Nominal k, Representational v) => Map k v = ...
Because of the universal instances, these constraints never get in the way. This is admittedly an abuse of existing constructs, but it seems so useful that it's worth a little abuse.
Change History (8)
comment:2 Changed 3 years ago by goldfire
- Milestone set to 7.8.1
- Status changed from new to merge
- Test Case set to roles/should_compile/T8958
comment:3 Changed 3 years ago by thoughtpolice
- Resolution set to fixed
- Status changed from merge to closed
comment:4 Changed 3 years ago by simonpj
- Owner goldfire deleted
- Resolution fixed deleted
- Status changed from closed to new