Pattern synonym fails with (Exp Bool) but works with (t ~ Bool => Exp t)
The following compiles just fine:
data Exp a where B :: Bool -> Exp Bool pattern Tru = B True pr :: Exp a -> String pr Tru = "true"
but add a signature to
pattern Tru :: Exp Bool pattern Tru = B True
…and it fails to compile
% ghci -ignore-dot-ghci /tmp/Bug.hs GHCi, version 188.8.131.5250316: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( /tmp/Bug.hs, interpreted ) /tmp/Bug.hs:11:4: Couldn't match type ‘a’ with ‘Bool’ ‘a’ is a rigid type variable bound by the type signature for pr :: Exp a -> String at /tmp/Bug.hs:10:7 Expected type: Exp a Actual type: Exp Bool Relevant bindings include pr :: Exp a -> String (bound at /tmp/Bug.hs:11:1) In the pattern: Tru In an equation for ‘pr’: pr Tru = "true" Failed, modules loaded: none.
Checking the inferred type of
pattern Tru = B True I get
ghci> :i Tru pattern Tru :: t ~ Bool => Exp t
which works as expected
pattern Tru :: t ~ Bool => Exp t pattern Tru = B True pr :: Exp a -> String pr Tru = "true"
|Component||Compiler (Type checker)|