|Reported by:||simonpj||Owned by:||cactus|
|Keywords:||PatternSynonyms||Cc:||lennart.augustsson@…, illissius@…, bgamari@…, cgibbard@…, gergo@…, tkn.akio@…, hvr@…, maoe@…, hackage.haskell.org@…|
|Type of failure:||None/Unknown||Test Case:|
|Blocked By:||Blocking:||#8582, #8583, #8584|
|Related Tickets:||Differential Rev(s):|
Lennart would like pattern synonyms. Something like
pattern con var1 … varN = pat
where ‘pattern` is a new keyword.
- Perhaps there should be a way to give a type as well, so the con could be (con :: type).
- The rhs is type checked as a usual pattern, i.e., in the global environment.
- The pat should bind exactly var1 .. varN.
- Recursive pattern synonyms are not allowed.
With con in scope it can be used like any other constructor in a pattern, and the semantics is simply by expansion.
It would have been very nice if con could be used in expressions as well, but I don’t see how that could work with view patterns. Perhaps view patterns could be extended to make them bidirectional.
My rationale for wanting pattern synonyms is that I sometimes have pattern matching with a lot of complex repetition in them. I’ve even resorted to using CPP in the past, and that just shows that Haskell is lacking some abstraction mechanism.
If pattern synonyms could be made to work in the presence of view pattern it would offer a mechanism for normal pattern matching on abstract types, since the abstract type could export some pattern synonyms and you’d not be able to tell of those were real constructors or not.
I’ve not tried implementing this, but I think SHE has something like it.
Change History (51)
comment:7 Changed 4 years ago by bgamari
- Cc bgamari@… added
- Type changed from bug to feature request
- Version 7.0.3 deleted
comment:25 in reply to: ↑ 23 ; follow-up: ↓ 27 Changed 3 years ago by cactus
comment:41 Changed 3 years ago by cactus
- Milestone changed from _|_ to 7.8.1
- Status changed from new to patch
comment:42 Changed 3 years ago by thoughtpolice
- Resolution set to fixed
- Status changed from patch to closed