Skip to content

Instantly share code, notes, and snippets.

@ohlawdie
Last active February 11, 2020 22:40
Show Gist options
  • Save ohlawdie/13bb45ca714a05c0b16f1a71568a825a to your computer and use it in GitHub Desktop.
Save ohlawdie/13bb45ca714a05c0b16f1a71568a825a to your computer and use it in GitHub Desktop.
ExplicitField VAL #F F# #Let
//Line 4 and 17
type MyType() =
let mutable myInt1 = 10
[<DefaultValue>] val mutable myInt2 : int
[<DefaultValue>] val mutable myString : string
member this.SetValsAndPrint( i: int, str: string) =
myInt1 <- i
this.myInt2 <- i + 1
this.myString <- str
printfn "%d %d %s" myInt1 (this.myInt2) (this.myString)
let myObject = new MyType()
myObject.SetValsAndPrint(11, "abc")
// The following line is not allowed because let bindings are private.
// myObject.myInt1 <- 20
myObject.myInt2 <- 30
myObject.myString <- "def"
printfn "%d %s" (myObject.myInt2) (myObject.myString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment