Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created August 13, 2017 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/487e7fddc6289892ac975e45e94cff73 to your computer and use it in GitHub Desktop.
Save deque-blog/487e7fddc6289892ac975e45e94cff73 to your computer and use it in GitHub Desktop.
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