Allow smart constructors their own types
|Reported by:||dfeuer||Owned by:|
|Type of failure:||None/Unknown||Test Case:|
|Related Tickets:||#8581||Differential Rev(s):|
GHC currently offers one-way pattern synonyms allowing general deconstruction with nice syntax. And it offers bidirectional pattern synonyms, which toss in construction functions that start with capital letters. Unfortunately, it forces the construction and deconstruction sides to share a type. This is sometimes rather unfortunate. The documentation itself points out the limitation with regard to matching numeric literals (where deconstruction requires
Eq). Another example is Edward Yang's
NF type, whose smart constructor (but not deconstructor) requires
NFData. I think the easiest fix is to allow a type signature in the
where clause of a pattern synonym definition.
pattern X :: Eq a => a -> Foo pattern X q <- ... where X :: X a => a -> Foo X a = ...
Ideally, I'd like to offer the other one-way (constructor without pattern) as well, but I care less about that. }}}