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

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Tue Jul 16 23:06:17 CEST 2013

On Tue, Jul 16, 2013 at 04:57:59PM -0400, 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?

You can always try

    data Cfg f = Cfg { verbose :: f Bool }

and set f to Maybe or Identity depending on what you use it for.  It will be
slightly notationally cumbersome to extract values from the Identity functor


More information about the Haskell-Cafe mailing list