I look at this example using getOpts, and one part of it really puzzles me: field label syntax.
First, it seems fairly simple by creating a data type and declaring initial values:
data Options = Options { optVerbose :: Bool
, optInput :: IO String
, optOutput :: String -> IO ()
}
startOptions :: Options
startOptions = Options { optVerbose = False
, optInput = getContents
, optOutput = putStr
}
Then it is getOptused to go through the options and determine the actual parameters for the running program using the command foldl... and then this expression expresses disappointment with me:
let Options { optVerbose = verbose
, optInput = input
, optOutput = output } = opts
After that, Boolean and functions are used verbose, inputand output. In most programming languages ββthat I'm familiar with, this step will be written something like this:
verbose = opts.optVerbose
input = opts.optInput
output = opts.optOutput
Is Haskell's behavior here somehow documented?