(* CS:3820, Fall 2016 *) (* Cesare Tinelli *) (* The University of Iowa *) (* F# examples seen in class *) (* Immutable record types *) type employeeType = { id : int ; name : string ; age : int ; salary : float ; dept : char } let e = { id = 1098; name = "Joe Bull"; age = 22; salary = 3400.4; dept = 'S' } e.name e.dept let { id = i; name = n } = e let e1 = { e with age = 40; dept = 'A' } e // semicolon separator can be replaced by a new line character let e = { id = 1098 name = "Joe Bull" age = 22 salary = 3400.4 dept = 'S' } (* Mutable record types *) type mut_rec = { mutable x : int ; y : int } let r = { x = 5; y = 3 } // assignment r.x <- 10 r r.y <- 110 type linkedList = { value : int ; mutable next : linkedList } // mutable variables let mutable z = 4 z <- 11 // while loops while (z > 0) do (printfn "%i\n" z; z <- z - 1) // semicolon separator can be replaced by a new line character // and indentation while (z > 0) do printfn "%i\n" z z <- z - 1