[GHC] #12428: Allow pattern synonyms to optionally carry coerceability
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature | Status: new request | Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Aside from their more interesting abilities, pattern synonyms can be used for name management. For example, if a module exports a type with a data constructor named `A`, and also re-exports a type with a data constructor named `A`, it can use a pattern synonym to rename the imported constructor. If the type is a `newtype`, this pattern synonym will not carry coerceability. Sometimes, this is exactly what one would desire (an "unsafe" module breaking through a newtype abstraction may wish to allow importers to confine coerceability). Other times, it's not (pattern synonym just for name control). When defining a pattern synonym for a type in a module in which that type is coerceable, it would be nice to be able to tell GHC that the pattern synonym should carry coerceability. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): Can you give a concrete examples? I’m not quite sure what you mean by “carry coerceability”, and how that is tied to pattern synonyms. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:1 nomeata]:
Can you give a concrete examples? I’m not quite sure what you mean by “carry coerceability”, and how that is tied to pattern synonyms.
Having a newtype constructor in scope in a module brings with it certain `Coercible` instances. There is no other way to bring those into scope globally in a module, although they can be used locally by matching on a `Coercion`. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Could you give a specific, concrete example? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:3 simonpj]:
Could you give a specific, concrete example?
Suppose I have a module that defines a newtype {{{#!hs newtype Foo a = Foo a }}} Suppose this module has a zillion users, and at some point its maintainer decides, for internal reasons, to change the definition of `Foo` to {{{#!hs newtype Foo a = Foo (Bar a) }}} where `Bar` is another newtype. She can expose a ''similar'' interface by hiding the `Foo` constructor and instead exporting a pattern synonym {{{#!hs pattern Foo a = Foo (Bar a) }}} But the interface is not quite the same! If someone has a module that imports hers and then uses the `Coercible a (Foo a)` instance, it will simply stop working now that the actual `Foo` constructor is no longer exported. What I'm proposing is that pattern synonym writers who can see the actual constructor should be able to "bless" their pattern synonyms with its magical import/export power, and that this should be available transitively. I ''don't'' want it to be automatic, because sometimes I explicitly want to use a pattern synonym to block coercions. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): I wonder if it makes sense to look at that feature request independently of pattern synonyms. Then it becomes:
Give library authors a way to allow newtype unwrapping for newtypes where the constructor is not imported.
or, a bit more concrete
Give library authors a way to allow newtype unwrapping for newtypes where the constructor is not imported, by naming other symbols (functions, constructors, pattern synonyms) that, if in scope, give the user of their library the power to do newtype unwrapping.
-- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Also there's a problem with {{{ pattern Foo a = Foo (Bar a) }}} because it looks recursive. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:6 simonpj]:
Also there's a problem with {{{ pattern Foo a = Foo (Bar a) }}} because it looks recursive.
That was just a mistake. Rename the new constructor `NewFoo` or something. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Joachim is right. This has really has nothing to do with pattern synonyms. It would apply just as much if instead of `pattern NewFoo` we offered {{{ getFoo :: Foo a -> a getFoo (Foo (Bar x)) = x }}} Now I suppose you might want to * Export the type `Foo` and function `getFoo`, but not the data constructors `Foo` and `Bar`. * And still get `(Coercible (Foo a) a)` in importing modules, although the relevant data constructors are not in scope. Yes, that's possible. If lots of people want it, I guess we can look for some way to control the export of the `Coercible` instance. But it's rather orthogonal to pattern synonyms. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12428: Allow pattern synonyms to optionally carry coerceability -------------------------------------+------------------------------------- Reporter: dfeuer | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * milestone: 8.2.1 => 8.4.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12428#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC