Opened 3 years ago

Closed 3 years ago

#12426 closed feature request (duplicate)

Allow smart constructors their own types

Reported by: dfeuer Owned by:
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.0.1
Keywords: PatternSynonyms Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #8581 Differential Rev(s):
Wiki Page:


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. }}}

Change History (2)

comment:1 Changed 3 years ago by mpickering

Keywords: PatternSynonyms added

This is essentially #8581.

comment:2 Changed 3 years ago by bgamari

Resolution: duplicate
Status: newclosed

Let's mark it as a duplicate in that case.

Note: See TracTickets for help on using tickets.