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 }