RecordWildCards

{-# LANGUAGE RecordWildCards #-}

data Client = Client { firstName     :: String
                     , lastName      :: String
                     , clientID      :: String 
                     } deriving (Show)

printClientName::Client -> IO ()
printClientName Client{..} = do
    putStrLn firstName
    putStrLn lastName
    putStrLn clientID

模式 Client{..} 引入构造函数 Client 的所有字段,并且等同于模式

Client{ firstName = firstName, lastName = lastName, clientID = clientID }

它也可以与其他字段匹配器结合使用,如下所示:

Client { firstName = "Joe", .. }

这相当于

Client{ firstName = "Joe", lastName = lastName, clientID = clientID }