This project is read-only.
Generic Type

Category:
Defining Types and Functions
Description: Define a generic type
Code:
type TrackedValue<'Kind>(v : 'Kind) =
let mutable value = v
let mutable reads = 0
let mutable writes = 0

member this.Value
with get() =
reads <- reads + 1
value
and set newVal =
writes <- writes + 1
value <- newVal

let GenericSample1() =
let a = TrackedValue(10)
let b = TrackedValue(20.0)
let c = TrackedValue<_>("Hello")
printfn "%d %f %s" a.Value b.Value c.Value

Execution Result:
10 20.000000 Hello

Last edited Sep 14, 2011 at 3:31 AM by ttliu2000, version 1

Comments

No comments yet.