[Haskell-cafe] Wrapping all fields of a data type in e.g. Maybe

Michael Orlitzky michael at orlitzky.com
Wed Jul 17 06:04:18 CEST 2013

On 07/16/2013 08:41 PM, John Lato wrote:
> The suggestion of parameterizing on a functor would be good, however
> there's another approach I've often seen (although it's not quite what
> you've asked for).  You can leave your config datatype alone, but
> instead of making it a monoid have your configuration parsers return
> functions with the type (Cfg -> Cfg).  You can wrap these functions in
> Endo to get a monoid, combine them together, and then apply that
> function to the default configuration.

I'm using cmdargs for the command-line parsing, and I think (if I don't
want to abandon its magic entirely) that I'm stuck filling a data
structure automatically.

I settled on using (Maybe Foo) so that the default value returned by
cmdargs will be Nothing if the user doesn't supply that option; if I use
a plain Cfg object, and the user doesn't pass --verbose, I'll get False
back in its place and then I don't know whether or not that should
override the config file (supposing the user has verbose=True in the file).

Very clever though.

More information about the Haskell-Cafe mailing list