I am looking at this example using getOpts, and one portion of it really baffles me: the syntax of field labels.
First, this seems simple enough, creating a data type and declaring the initial values:
data Options = Options { optVerbose :: Bool
, optInput :: IO String
, optOutput :: String -> IO ()
}
startOptions :: Options
startOptions = Options { optVerbose = False
, optInput = getContents
, optOutput = putStr
}
Then getOpt
is used to go through the options and determine the actual parameters for the running program using a foldl
command... and then this let expression frustrates me:
let Options { optVerbose = verbose
, optInput = input
, optOutput = output } = opts
The boolean and functions verbose
, input
, and output
are then used after this. In most of the programming languages I'm more familiar with, this step would be written something like so:
verbose = opts.optVerbose
input = opts.optInput
output = opts.optOutput
Is Haskell's behavior here documented someplace?