Define a mutable record

Category:
Defining Types
Description: Define a mutable record
Code:
type Employee = 
{ Name : string;
StartDate : string;
mutable Salary : float }

let TypeRecordSample1() =
let steve = { Name = "Steve"; StartDate = "01 Jan 2000"; Salary = 30000.0 }
let joe = { Name = "Joe"; StartDate = "25 Dec 2001"; Salary = 45000.0 }

let giveRaise (emp : Employee, increase : float ) =
emp.Salary <- (1.0 + increase)*emp.Salary
printfn "%s: Salary=%f" emp.Name emp.Salary

giveRaise (steve, 0.05)
giveRaise (joe, 0.10)

//--------------------------------------------------------

Execution Result:
Steve: Salary=31500.000000
Joe: Salary=49500.000000

Last edited Sep 14, 2011 at 2:59 AM by ttliu2000, version 1

Comments

No comments yet.