Pattern Synonyms and type families
Haskell Community [Unofficial]
May 31, 2026
Hi,
I tried to use a pattern synonym with a type family and got the following GHC error:
Pattern synonym ‘ZeroAB’ cannot be used here
(pattern synonyms cannot be promoted)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE UndecidableInstances #-}
data AB = Ab { a :: Nat, b :: Nat}
pattern ZeroAB = Ab 0 0
type family Tf ab where
Tf ZeroAB = Ab 1 1
Tf _ = Ab 0 0
I haven’t found a corresponding issue on the GHC GitLab tracker, nor any discussion of this from the perspective of a potential language feature.
I think it could be useful to have a GHC extension that allows this capability. The syntax of type families is fairly limited, and switching from an atomic type parameter to a record type parameter often introduces additional boilerplate. Being able to reuse pattern synonyms at the type level could help make type-family definitions more concise and maintainable.
Discussion in the ATmosphere