Created
February 21, 2019 10:59
-
-
Save Gryff/2480f9ce8ae9d5b8683a053d80763b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- our bank functions | |
deposit :: Int -> State [Transaction] () | |
deposit amount = modify (\transactions -> transactions ++ [Deposit amount]) | |
withdraw :: Int -> State [Transaction] () | |
withdraw amount = modify (\transactions -> transactions ++ [Withdrawal amount]) | |
getStatement :: State [Transaction] String | |
getStatement = gets generateStatement -- the details of generateStatement are out of scope of this post | |
-- and here's the usage | |
main = do | |
let statement = evalState useMyBank [] | |
print statement | |
useMyBank :: State [Transaction] String | |
useMyBank = do | |
deposit 200 | |
withdraw 100 | |
getStatement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment