(* sml object oriented bank accounts *) fun newaccount () = let val bal = ref(0) in let fun deposit x = (bal := !bal + x; !bal); in let fun withdraw x = (bal := !bal - x; !bal); in let fun gateway method arg = if (method="withdraw") then (withdraw arg) else if (method="deposit") then (deposit arg) else (!bal); in gateway end end end end; val myaccount = newaccount (); val youraccount = newaccount (); myaccount "deposit" 500; youraccount "deposit" 500; myaccount "withdraw" 30; youraccount "withdraw" 50;