Created
April 1, 2017 23:04
-
-
Save rhom6us/da4d74794d84b3609362c9bc45a675b2 to your computer and use it in GitHub Desktop.
F# Records - Default Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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