[Haskell-cafe] Parsing arguments and reading configuration
magnus at therning.org
Fri Sep 19 18:24:19 EDT 2008
I'm looking for some inspiration for an elegant solution to a silly
little problem I have. This might have a general well-known solution,
or maybe there's something particularly elegant possible in Haskell. I
just thought I'd ask.
When writing a command line tool I want to use a configuration file and
then have the ability to override the configuration using command line
arguments. When I've worked with command line arguments before I've
used the trick of folding (>>=) over a list of functions that modify the
"members" of a type, using the default values as the starting point. I
like that, it's cute.
First I thought I'd treat the configuration in a similar way, but then I
noticed a slight ordering problem. The command line arguments should
take priority over the contents of the configuration file, but the
location of the configuration can be given as an argument. I could read
the arguments twice, first to get the correct location of the config
file, then load the config, and then read the arguments again to make
sure they take priority. But that feels a little silly. Are there any
more elegant solutions people are using?
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnus＠therning．org Jabber: magnus＠therning．org
Haskell is an even 'redder' pill than Lisp or Scheme.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080919/7d14ae61/signature.bin
More information about the Haskell-Cafe