[
[
type BankAccount<[
let mutable balance : float<'u> = 0.0<_>
member acct.HasLotsOfMoney = balance > (LanguagePrimitives.FloatWithMeasure 10000.0) //10000 units
member acct.Deposit(amt) = balance <- balance + amt
member acct.Withdraw(amt) = balance <- balance - amt
let MeasureSample5() =
let a = BankAccount
a.Deposit(10.
let b = BankAccount
b.Deposit(10.
printfn "show how to deposit right currency to right account"
If you change the deposit incorrect currency into the account, you will get a compile time error. The tricky part is to use LanguagePrimitives.FloatWithMeasure in the sample. please make sure all constant in the type definition is always use LanguagePrimitives.FloatWithMeasure.
No comments:
Post a Comment