Skip to content

[Regression] Only one clause allowed in (explicitly bidirectional) pattern synonyms

Regression. This worked in 7.10.2:

{-# LANGUAGE PatternSynonyms, ViewPatterns #-}

pattern A :: Int -> String
pattern A n <- (read -> n) where
        A 0 = "hi"
        A 1 = "bye"

Removing the final clause works in GHC head but given the same code it claims the clause is empty:

% ghci -ignore-dot-ghci /tmp/tmp.t0h0pMgwWb.hs
GHCi, version 8.1.20160105: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( /tmp/tmp.t0h0pMgwWb.hs, interpreted )

/tmp/tmp.t0h0pMgwWb.hs:4:9: error:
    pattern synonym 'where' clause cannot be empty
    In the pattern synonym declaration for:  A
Failed, modules loaded: none.
Prelude> 

The where clause is certainly not empty — ironically seems to be caused by my very own #10426 (closed) (D1665) :--) hoist by my own ticket as we say:

 ; when (length matches /= 1) (wrongNumberErr loc)

Personally a trailing where is quite alright and handy when quickly checking if a declaration is otherwise OK. It works for data/newtype declarations as well as type classes. A workaround is to pattern match in other ways:

pattern A n <- ... where
        A = \case
          0 -> "hi"
          1 -> "bye"
Edited by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information