Home > database >  Haskell: Default empty fields to value
Haskell: Default empty fields to value

Time:07-11

When constructing an instance using Pattern {} in Haskell you must define all fields.

A lot of the time I find myself filling most of these fields with some default value, usually the same as the values in mempty if I have defined monoid.

Is there any syntax in Haskell to construct an instance using {} but defaulting to the fields of another instance if not present.

Something like mempty with {...}.

CodePudding user response:

Just use a variable with the other instance in place of the data constructor, like this: mempty{ someField = 123 }.

  • Related