Skip to content

Pattern synonyms allow multiple type signatures but only use the first

GHC seems to only be using the first signature for pattern synonyms

GHC 8.0.2 allows this to compile:

{-# LANGUAGE PatternSynonyms #-}
module Pattern where

pattern Foo :: ()
pattern Foo :: Bool
pattern Foo = ()

but not this:

{-# LANGUAGE PatternSynonyms #-}
module Pattern where

pattern Foo :: Bool
pattern Foo :: ()
pattern Foo = ()

This compiles and ghci tells me the type of Foo is ():

{-# LANGUAGE PatternSynonyms #-}
module Pattern where

pattern Foo :: ()
pattern Foo :: Bool
pattern Foo <- _
  where Foo = undefined

This doesn't compile (as expected):

{-# LANGUAGE PatternSynonyms #-}
module Pattern where

pattern Foo :: ()
pattern Foo :: Bool Bool
pattern Foo = ()
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information