Haskell Language Record Syntax RecordWildCards


Example

{-# 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

The pattern Client{..} brings in scope all the fields of the constructor Client, and is equivalent to the pattern

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

It can also be combined with other field matchers like so:

Client { firstName = "Joe", .. }

This is equivalent to

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