In the 1.3 libraries, the contents of the command-line can be got at
with (System.getArgs :: IO [String]), which you then can peer at
intensely to find out what the user really wanted:
main =
do
argv <- System.getArgs
let
(parser_opts,
reader_opts,
simpl_opts) = decipherArgv argv
in
...
parse parser_opts ...
...
However, passing around option values to the different parts of your
program is a major bore, so what about instead treating argv for what
it really is, a constant, and make it available as such
(System.argv :: [String]), say. Having it as constant has the nice
property that your program's option values can now be turned into
CAFs, and you'll avoid all the pains of plumbing, i.e.,
my_opts = decipherArgv System_argv
parser_opts = getParserOpts my_opts
..
simpl_opts = getSimplifierOpts my_opts
fname = getFileName my_opts
main =
do
hndl <- openFile fname
...
ast <- parser hndl
...
I know you could go wild with monads, c. classes etc. and try to
squirrel away these things, but argv is a constant (in a sane world),
so why not treat it as such (ditto for the environment)? Thoughts?
--sigbjorn