Aggreate type and LanguagePrimitives

Category:
Units of Measure
Description: Aggreate type and LanguagePrimitives. The LanguagePrimitives is used to make a number (e.g. float) into units of measure.
Code:
[<Measure>]type JPY
[<Measure>]type CNY
type BankAccount<[<Measure>]'u>() =
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<JPY>()
a.Deposit(10.<JPY>)

let b = BankAccount<CNY>()
b.Deposit(10.<CNY>)

printfn "show how to deposit right currency to right account"

Execution Result:
show how to deposit right currency to right account

Last edited Sep 23, 2011 at 2:18 AM by ttliu2000, version 3

Comments

No comments yet.