Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created March 11, 2017 23:00
Show Gist options
  • Save mjgpy3/92e5b4856c6c7e76b3b1dc8c01794fd4 to your computer and use it in GitHub Desktop.
Save mjgpy3/92e5b4856c6c7e76b3b1dc8c01794fd4 to your computer and use it in GitHub Desktop.
F# Inheritance Example
type Person(name: string) =
member this.GetName () = name
type Employee(name: string, id: int) =
inherit Person(name)
member this.GetId () = id
member val Id = id with get, set
member this.SetId (newId: int) =
this.Id <- newId
let steve = Employee ("Steve", 666)
let toString (e: Employee) =
sprintf "name=%s, id=%d" (e.GetName ()) e.Id
printfn "%s" (toString steve)
steve.Id <- 6666
printfn "%s" (toString steve)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment