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

Michael Orlitzky michael at orlitzky.com
Wed Jul 17 01:43:45 CEST 2013

On 07/16/2013 05:06 PM, Tom Ellis wrote:
> 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
> though.

Two votes for this approach. I'll give it a try and see whether it comes
out more or less verbose. Thanks!

More information about the Haskell-Cafe mailing list