On 07/16/2013 04:57 PM, Michael Orlitzky wrote:
> 
> This all works great, except that when there's 20 or so options, I
> duplicate a ton of code in the definition of OptionalCfg. Is there some
> pre-existing solution that will let me take a Cfg and create a new type
> with Cfg's fields wrapped in Maybe?
> 

For posterity, I report failure =)

If I parameterize the Configuration type by a functor, it breaks the
DeriveDataTypeable magic in cmdargs. The resulting manual definitions
along with the lenses to look inside the Identity functor well exceed
the duplicated code from OptionalCfg.

Combining the option parsing and config file parsing increases the
amount of code in the command-line parser by roughly an equal amount,
but in my opinion a worse consequence is that it conflates two unrelated
procedures. I very much like this:

  rc_cfg  <- from_rc
  cmd_cfg <- apply_args
  let opt_config = rc_cfg <> cmd_cfg
  ...

All things considered the duplicated data structure seems like the least
of three evils.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to