[GHC] #5144: Pattern synonyms
GHC
ghc-devs at haskell.org
Thu Aug 22 12:01:30 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):
Replying to [comment:25 cactus]:
> > 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
>
> What if you could just export `pattern P` (where `P` is the name of the
data constructor) without having to define `AbsP`? Would that be taking
things too far?
That would treat pattern synonyms and data constructors differently, which
I am keen to avoid. Under what you propose:
* If P is a data constructor then `pattern P` would export P uni-
directionally (pattern only)
* If P is a (bi-directonal) pattern synonym then `pattern P` would export
P bi-directionally.
I don't like that... a data constructor is precisely a (degenerate)
bidirectional pattern.
I suppose you could put the directionality in the export list:
{{{
module M(
pattern P, -- Uni-directional
constructor Q -- Bidirectional
) where
pattern P x = [x]
pattern Q y = [y,y]
}}}
But I don't want to go this way. If you export P you get all of what P
is. Otherwise we'll get into exporting it unidirectionally from one
module, bidirectionally from another, then importing both of those, and
combining the directinoality of those imports. Too complicated.
Maybe `datacon P`, or `view P`, rather than `pattern P` would address
Ian's worry?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/5144#comment:27>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list