This project is read-only.
More Basic Records

Category:
Defining Types
Description: Examples of cloning records using 'with' keyword and accessing record fields using . (dot).
Code:
type simpleRecord = {Name: string; Job: string; Wage: int}

let RecordSample2() =
let worker = { Name = "Bill"; Job = "Cashier"; Wage = 20 }

let worker2 = { worker with Name = "John"; Wage = 15 }

printfn "%s is a %s and makes $%d per hour" worker.Name worker.Job worker.Wage
printfn "\n%s is a %s and makes $%d per hour" worker2.Name worker2.Job worker2.Wage

Execution Result:
Bill is a Cashier and makes $20 per hour

John is a Cashier and makes $15 per hour

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

Comments

No comments yet.