Bank Account in Haskell
Simulate a bank account supporting opening/closing, withdraws, and deposits of money. Watch out for concurrent transactions!
exercism fetch haskell 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.
Run the test file, and fix each of the errors in turn. When you get the first test to pass, go to the first pending or skipped test, and make that pass as well. When all of the tests are passing, feel free to submit.
Remember that passing code is just the first step. The goal is to work towards a solution that is as readable and expressive as you can make it.
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.
For installation and learning resources, refer to the exercism help page.
Running the tests
To run the test suite, execute the following command:
If you get an error message like this...
No .cabal file found in directory
You are probably running an old stack version and need to upgrade it.
Otherwise, if you get an error message like this...
No compiler found, expected minor version match with... Try running "stack setup" to install the correct GHC...
Just do as it says and it will download and install the correct compiler version:
If you want to play with your solution in GHCi, just run the command:
Feedback, Issues, Pull Requests
The exercism/haskell repository on GitHub is the home for all of the Haskell exercises.
If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue. We'll do our best to help you!
Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.