TH-spliced pattern synonym declaration fails to typecheck
This pattern synonyms typechecks without issue:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
module Works where
data T a where
MkT :: Eq b => b -> T a
pattern P :: b -> T a
pattern P x <- MkT x
But if you try to create P
from a Template Haskell splice, it will fail to typecheck:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TemplateHaskell #-}
module Bug where
data T a where
MkT :: Eq b => b -> T a
$([d| pattern P :: b -> T a; pattern P x <- MkT x |])
$ /opt/ghc/head/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:3: error:
• Couldn't match expected type ‘b0’ with actual type ‘b’
‘b’ is a rigid type variable bound by
a pattern with constructor: MkT :: forall a b. Eq b => b -> T a,
in a pattern synonym declaration
at Bug.hs:9:3-52
‘b0’ is a rigid type variable bound by
the signature for pattern synonym ‘P’ at Bug.hs:9:3-52
• In the declaration for pattern synonym ‘P’
• Relevant bindings include x_a4tP :: b (bound at Bug.hs:9:3)
Trac metadata
Trac field | Value |
---|---|
Version | 8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | PatternSynonyms |
Operating system | |
Architecture |