I have the following code:
type transaction = Withdraw of int | Deposit of int | Checkbalance
(* Bank account generator. *)
let make_account(opening_balance: int) =
let balance = ref opening_balance in
fun (t: transaction) ->
match t with
| Withdraw(m) -> if (!balance > m)
then
((balance := !balance - m);
(Printf.printf "Balance is %i" !balance))
else
print_string "Insufficient funds."
| Deposit(m) ->
((balance := !balance + m);
(Printf.printf "Balance is %i\n" !balance))
| Checkbalance -> (Printf.printf "Balance is %i\n" !balance)
;;
whenever I try to run the following command: make_account(100) Deposit(50) ;; I get the following error: This function has type int -> transaction -> unit. It is applied to too many arguments; maybe you forgot a `;'.
However the following command works just fine Deposit(50) |> make_account(100) ;;
But why aren't these two line of codes equivalent? shouldn't (make_account 100) be replaced by (fun (t: transaction) -> ...) ? Because then I don't understand why my first attempt did not work.
Thank you!