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 :: type).
rhsis type checked as a usual pattern, i.e., in the global environment.
patshould bind exactly
- Recursive pattern synonyms are not allowed.
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.