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

#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

#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
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Richard Eisenberg

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | goldfire Priority: normal | Status: merge Component: Compiler | Milestone: 7.8.1 Resolution: | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: roles/should_compile/T8958 | Architecture: Blocking: | Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Changes (by goldfire): * status: new => merge * testcase: => roles/should_compile/T8958 * milestone: => 7.8.1 Comment: This commit also fixed a latent bug in that the datatype context was not fully zonked in tcDataDefn. Please merge if possible into 7.8.1 -- this tiny patch allows lightweight role annotations, all done in user space, as suggested by Mark Lentczner. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | goldfire Priority: normal | Status: closed Component: Compiler | Milestone: 7.8.1 Resolution: fixed | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: roles/should_compile/T8958 | Architecture: Blocking: | Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Merged, thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | Status: new Priority: normal | Milestone: 7.8.1 Component: Compiler | Version: Resolution: | 7.8.1-rc2 Operating System: Unknown/Multiple | Keywords: Type of failure: None/Unknown | Architecture: Test Case: roles/should_compile/T8958 | Unknown/Multiple Blocking: | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Changes (by simonpj): * owner: goldfire => * status: closed => new * resolution: fixed => Comment: I can see the motivation here, though it is a grievous hack. But it needs documenting in the user manual! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | goldfire Priority: normal | Status: new Component: Compiler | Milestone: 7.8.1 Resolution: | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: roles/should_compile/T8958 | Architecture: Blocking: | Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Changes (by simonpj): * owner: => goldfire -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | goldfire Priority: normal | Status: closed Component: Compiler | Milestone: 7.8.1 Resolution: fixed | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: roles/should_compile/T8958 | Architecture: Blocking: | Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Changes (by goldfire): * status: new => closed * resolution: => fixed Comment: The code in the original post is indeed a grievous hack, but the change in GHC in order to support it is not. Indeed, when Mark first suggested this approach, I thought it was too unprincipled to incorporate. However, the only change needed within GHC to support the idea in the original post is that role inference must look at datatype contexts. This is sensible, all on its own. In fact, the user manual, as originally written for role inference, needs no change: it states that role inference propagates role information from every place a type is used, which naturally includes a datatype context. Now with this support in GHC, the grievous hack in my original post can be built in user-land. I have released it as a package `no-role-annots`. I don't really like it, but it seems to cause no harm and some might find it useful. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts -----------------------------------------------+--------------------------- Reporter: goldfire | Owner: Type: feature request | goldfire Priority: normal | Status: closed Component: Compiler | Milestone: 7.8.1 Resolution: fixed | Version: Operating System: Unknown/Multiple | 7.8.1-rc2 Type of failure: None/Unknown | Keywords: Test Case: roles/should_compile/T8958 | Architecture: Blocking: | Unknown/Multiple | Difficulty: Unknown | Blocked By: | Related Tickets: -----------------------------------------------+--------------------------- Comment (by simonpj): Fair enough. You are arguing that nothing belongs in the user manual because there is no special compiler behaviour. Yet a user approaching roles might still miss all of this. We have a mechanism for this: a wike page at Haskell.org. The "Documentation" link on [http://www.haskell.org/ghc/ GHC's home page] gets you [http://www.haskell.org/haskellwiki/GHC here]. The "Collaborative documentation" section is for user-level documentation about how to use GHC, above and beyond the user manual. In particular there is user-level documentation for [http://www.haskell.org/haskellwiki/GHC/Type_system type system extensions]. So that would be an excellent place for some user- facing documentation about roles, including a pointer to your library. I'm not suggesting that it's your responsibility to write such a page; but starting one, with an invitation to others to add more, would be an excellent move. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8958#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8958: Allow role inference on datatype contexts
-----------------------------------------------+---------------------------
Reporter: goldfire | Owner:
Type: feature request | goldfire
Priority: normal | Status: closed
Component: Compiler | Milestone: 7.8.1
Resolution: fixed | Version:
Operating System: Unknown/Multiple | 7.8.1-rc2
Type of failure: None/Unknown | Keywords:
Test Case: roles/should_compile/T8958 | Architecture:
Blocking: | Unknown/Multiple
| Difficulty: Unknown
| Blocked By:
| Related Tickets:
-----------------------------------------------+---------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC