[GHC] #5144: Pattern synonyms
GHC
ghc-devs at haskell.org
Thu Aug 22 11:37:47 UTC 2013
#5144: Pattern synonyms
-------------------------------------+------------------------------------
Reporter: simonpj | Owner: cactus
Type: feature request | Status: new
Priority: normal | Milestone: _|_
Component: Compiler | Version:
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 simonpj):
We must treat data constructors uniformly with pattern synonyms. For
example, it should definitely be OK to have
{{{
module M( pattern P, foo, bar ) where
-- The "pattern P" exports data constructor P
data T = P | Q
foo :: T
foo = P
bar :: T -> Int
bar P = 1
bar Q = 2
module A where
import M
-- T is not in scope
w1 = bar P -- Uses P as an expression
w2 = case foo of
P -> 1 -- Uses P as a pattern
}}}
We have at various times discussed how to allow a module to export a data
constructor that can be used as a ''pattern'' but not as a ''constructor''
(in expressions), because the data type is abstract and you should only
use a smart constructor. With pattern synonyms you can (almost) do that:
{{{
module M( T, pattern AbsP, pattern Q ) where
data T = P Int | Q
pattern AbsP = P
}}}
But I really wanted `AbsP` to be uni-directional and according to the
current spec [wiki:PatternSynonyms] it is "implicitly bidirectional". I
suggest we allow the user to control whether a pattern synonym is
bidirectional or not. I'm not sure what syntax to use for that. We want
to be able to say
* Uni-directional pattern synonym
* Bi-directional pattern synonym
* Bi-directional pattern synonym with explicit user code for the reverse
direction
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/5144#comment:23>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list