Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
add :: Money -> Money -> Maybe Money
add m1 m2 =
if currency m1 != currency m2 -- If the two currencies are different
then Nothing -- * Return an empty result
else Just $ Money { -- * Else return a new Money instance
amount = amount m1 + amount m2, -- which is the sum of the two inputs
currency = currency m1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment