程序代写 (* Records *)

(* Records *)

(* Defining records *)
type host_info =

Copyright By PowCoder代写 加微信 powcoder

{ hostname : string
; os_name : string
; cpu_arch : string
; timestamp : int

(* Creating records *)
let my_host = {hostname = “Emmy” ; os_name = “MacOS” ; cpu_arch = “X86” ; timestamp = 1507848368}

(* Extracting data from records *)
let the_name = my_host.hostname

(* Functional update of a record, this creates a new copy of the record! NOT UPDATE *)
let my_new_host = {my_host with os_name = “Linux”} (* A new copy of the value is created with one value of difference *)

(* Mutable records *)

type theme_park =
{ ride_name : string
; mutable num_of_riders : int (* If a field says mutable it contains a reference *)

(* Mutable fields are created just as regular fields *)
let mgr = {ride_name = “Merry go round” ; num_of_riders = 0}

(* References are updated with the <- instead of the := *) let click ride = ride.num_of_riders <- ride.num_of_riders + 1 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com