This project is read-only.
Aggreate type and LanguagePrimitives

Units of Measure
Description: Aggreate type and LanguagePrimitives. The LanguagePrimitives is used to make a number (e.g. float) into units of measure.
[<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>()

let b = BankAccount<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 3:18 AM by ttliu2000, version 3


No comments yet.