[GHC] #8958: Allow role inference on datatype contexts

GHC ghc-devs at haskell.org
Sat Apr 5 17:38:07 UTC 2014


#8958: Allow role inference on datatype contexts
------------------------------------+-------------------------------------
       Reporter:  goldfire          |             Owner:  goldfire
           Type:  feature request   |            Status:  new
       Priority:  normal            |         Milestone:
      Component:  Compiler          |           Version:  7.8.1-rc2
       Keywords:                    |  Operating System:  Unknown/Multiple
   Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
     Difficulty:  Unknown           |         Test Case:
     Blocked By:                    |          Blocking:
Related Tickets:                    |
------------------------------------+-------------------------------------
 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.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8958>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list