{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} -- A space is used instead of `--` because Haskell's -- standard library has no `splitOn` function :( applyCustomerId :: String -> String applyCustomerId name = name ++ " 23098234908" unapplyCustomerId :: String -> Maybe String unapplyCustomerId str = case words str of (name:_) -> Just name _ -> Nothing pattern CustomerId :: String -> String pattern CustomerId name <- (unapplyCustomerId -> Just name) main = case applyCustomerId "Sukyoung" of CustomerId name -> putStrLn name _ -> putStrLn "Could not extract a CustomerID"