fork download
  1. type BankAccount(initialSold : float, Owner : string) =
  2. let TransactHistory : string [] = null
  3. member val Sold = initialSold with get, set
  4. member this.Owner = Owner
  5. member this.DoTransaction(t : TransactionType) =
  6. match t with
  7. | Deposit amount -> this.Sold <- (this.Sold + amount)
  8. | Withdraw amount -> this.Sold <- (this.Sold - amount)
  9. | Transfer (target, amount) -> this.Sold <- (this.Sold - amount); target.Sold <- (target.Sold + amount)
  10.  
  11. override this.ToString() =
  12. this.Owner + " has " + this.Sold.ToString() + " $."
  13.  
  14. and TransactionType =
  15. | Deposit of float
  16. | Withdraw of float
  17. | Transfer of BankAccount * float
  18.  
  19.  
  20. let one = BankAccount(12.0,"First")
  21. one |> printfn "%A"
  22. one.DoTransaction (Deposit(2.0))
  23. one.DoTransaction (Withdraw(3.0))
  24.  
  25. one |> printfn "%A"
Success #stdin #stdout 0.17s 26264KB
stdin
Standard input is empty
stdout
First has 12 $.
First has 11 $.