module PatSyn whereimport PatSynEf1 :: [a] -> (a, [a])f1 (Sings a as) = (a, as)f2 :: [a] -> af2 (Sing a) = apattern Dup :: Eq a => a -> [a]pattern Dup a <- (dup -> (Just a)) where Dup a = [a, a]dup :: (Eq a) => [a] -> Maybe adup [x,x'] | x==x' = Just xdup _ = Nothingf3 :: [Int] -> Intf3 (Dup x) = xf3 _ = 0f4 :: Int -> Intf4 One = 99f4 _ = 88data S b = forall a . Show a => S (a,b)instance Show b => Show (S b) where show (S xy) = show xypattern SP :: () => Show a => a -> S Boolpattern SP a = S (a, True)f5 :: S Bool -> Stringf5 (SP x) = show xss :: S Boolss = S ((), True)----data T a = forall b . Show b => MkT a bpattern ExNumPat1 :: (Num a, Eq a) => (Show b) => b -> T apattern ExNumPat1 x = MkT 42 xpattern ExNumPat2 x = MkT 42 xft1 :: (Eq a, Num a) => T a -> Stringft1 (ExNumPat1 x) = show xft2 :: (Eq a, Num a) => T a -> Stringft2 (ExNumPat2 x) = show xmain :: IO ()main = do print $ Sing 1 print $ Swap 1 2 print $ f1 [3] print $ f2 [4]-- print (Sings 1 [2]) this is an error, of course print (Dup 22) print $ f3 [11,11] print $ f3 [11,12] print (One :: Int) print (One :: Double) print $ f4 1 print $ f4 2 print $ SP () print $ f5 ss let x = MkT 42 True y = ExNumPat1 () z = ExNumPat2 () print (ft1 x, ft2 x) print (ft1 y, ft2 y) print (ft1 z, ft2 z) print AA case A of AA -> print 42