{-# LANGUAGE PatternSynonyms #-} newtype CaseFree = CaseFree_ (String, Int) deriving (Show, Eq, Ord) pattern CaseFree :: String -> Int -> CaseFree pattern CaseFree a b <- CaseFree_ (a, b) getStr :: CaseFree -> String getStr (CaseFree str _) = str getBits :: CaseFree -> Int getBits (CaseFree _ bits) = bits ignore :: CaseFree -> String ignore (CaseFree _ _) = "Ignored." main :: IO () main = do mapM_ putStrLn [ getStr (CaseFree_ ("abc", 0)) , show (getBits (CaseFree_ ("abc", 0))) , ignore (CaseFree_ ("foo", 1)) ]