I'm now trying out 2 pieces of code from:
https://mpickering.github.io/posts/2015-12-12-pattern-synonyms-8.html
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE GADTs #-}
In the first piece of code:
pattern IsTrue :: Show a => a
pattern IsTrue <- ((== "True") . show -> True)
test10 = IsTrue "True"
The following error was thrown:
? non-bidirectional pattern synonym ‘IsTrue’ used in an expression
? In the expression: IsTrue "True"
In the second piece of code:
data T where
MkT :: (Show b) => b -> T
pattern ExNumPat :: () => Show b => b -> T
pattern ExNumPat x = MkT x
test11 = ExNumPat True
The following error was thrown when I run test11
:
? No instance for (Show T) arising from a use of ‘print’
What caused these 2 errors and how do I resolve them? And how do the patterns work?
See Question&Answers more detail:os