Skip to content

A shorter COMPLETE pragma syntax for pattern synonyms that replace specific constructors

If I have a data type with many constructors and a pattern synonym that can be used instead of a single constructor, I currently have to list all the remaining constructors in the COMPLETE pragma. This is onerous, unreadable, and requires that I update the COMPLETE pragma whenever I add another constructor.

{-# language PatternSynonyms #-}
module M where

data D = C1 | C2 | C3 -- and so forth

{-# COMPLETE P, C2, C3 ... #-}
pattern P = C1

Instead I would like to concisely describe the constructors that my pattern synonym can substitute. For example:

{-# SUBSTITUTE P (C1) #-}
pattern P = C1

If a pattern synonym substitutes multiple constructors it could look like this:

{-# SUBSTITUTE P (C1, C2) #-}
Edited by Simon Jakobi
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information