Bank Account
Bank Account

Bank Account



Simulate a bank account supporting opening/closing, withdrawals, and deposits of money. Watch out for concurrent transactions!

A bank account can be accessed in multiple ways. Clients can make deposits and withdrawals using the internet, mobile phones, etc. Shops can charge against the account.

Create an account that can be accessed from multiple threads/processes (terminology depends on your programming language).

It should be possible to close an account; operations against a closed account must fail.

To complete this exercise you need to implement the following functions:

  • openAccount - Called at the start of each test. Returns a BankAccount.
  • closeAccount - Called at the end of each test.
  • getBalance - Get the balance of the bank account.
  • updateBalance - Increment the balance of the bank account by the given amount.

The amount may be negative for a withdrawal.

The initial balance of the bank account should be 0.

You will find a dummy data declaration and type signatures already in place, but it is up to you to define the functions and create a meaningful data type, newtype or type synonym.

If you need help, here are some additional resources:

Edit via GitHub The link opens in a new window or tab
Haskell Exercism

Ready to start Bank Account?

Sign up to Exercism to learn and master Haskell with 107 exercises, and real human mentoring, all for free.