Skip to content

Instantly share code, notes, and snippets.

@Gryff
Created February 21, 2019 10:59
Show Gist options
  • Save Gryff/2480f9ce8ae9d5b8683a053d80763b9a to your computer and use it in GitHub Desktop.
Save Gryff/2480f9ce8ae9d5b8683a053d80763b9a to your computer and use it in GitHub Desktop.
-- 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