jtdaugherty / vty

A high-level ncurses alternative written in Haskell
BSD 3-Clause "New" or "Revised" License
320 stars 57 forks source link

A simpler version of the Semigroup instance for MaybeDefault #225

Closed KommuSoft closed 3 years ago

KommuSoft commented 3 years ago

The implementation of the Semigroup has less clauses, but I think it is also more descriptive since the code "explains" how the semigroup works whereas in the original version it exhaustively enumerated over the items, but without explaining the rules of the semigroup.

Likely the implementation is also slightly more memory efficient, since we return the SetTo _ parameter, not constructing a new equivalent one. The implementation is also more lazy, since we never evaluate the first parameter here. If the second item is thus Default or SetTo _ we will never evaluate the first parameter.

A test is created to check if the implementation is equivalent to the old Semigroup instance.

jtdaugherty commented 3 years ago

Thank you!