Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Haskell: Default empty fields to value

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Something like mempty with {...}.

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading