Skip to content

Instantly share code, notes, and snippets.

@Richard-Degenne
Created July 3, 2017 15:32
Show Gist options
  • Save Richard-Degenne/ce2c83730d22133370d7588af2dde908 to your computer and use it in GitHub Desktop.
Save Richard-Degenne/ce2c83730d22133370d7588af2dde908 to your computer and use it in GitHub Desktop.
OCaml functional update example
type coordinates = {x: int; y: int} (* Define a record type for coordinates *)
type player = {name: string; coordinates: coordinates} (* Define a record type for players *)
let richou = {name = "Richou"; coordinates = {x=0; y=0}} (* Define a new player *)
(* This is called a functional update.
* It creates a new record "based on" an existing record.
*)
let richou2 = {richou with coordinates = {x=1; y=1}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment