Skip to content

Instantly share code, notes, and snippets.

@rhom6us
Created April 1, 2017 23:04
Show Gist options
  • Save rhom6us/da4d74794d84b3609362c9bc45a675b2 to your computer and use it in GitHub Desktop.
Save rhom6us/da4d74794d84b3609362c9bc45a675b2 to your computer and use it in GitHub Desktop.
F# Records - Default Values
// Rather than use [<DefaultValue>], define a default record.
type MyRecord = {
field1 : int
field2 : int
}
let defaultRecord1 = { field1 = 0; field2 = 0 }
let defaultRecord2 = { field1 = 1; field2 = 25 }
// Use the with keyword to populate only a few chosen fields
// and leave the rest with default values.
let rr3 = { defaultRecord1 with field2 = 42 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment