Skip to content

Instantly share code, notes, and snippets.

@SchlenkR
Created May 14, 2020 14:58
Show Gist options
  • Save SchlenkR/c7fdcb51ed490671230bb8f5014ea4eb to your computer and use it in GitHub Desktop.
Save SchlenkR/c7fdcb51ed490671230bb8f5014ea4eb to your computer and use it in GitHub Desktop.
An F# record that implements an interface
type IDisplayable =
abstract GetDisplayText: unit -> string
type Person =
{ age: int
name: string }
interface IDisplayable with
member x.GetDisplayText() = x.name
let showValue (x: IDisplayable) =
printfn "Hello %s" (x.GetDisplayText())
// Test
let x = { age = 22; name = "Hans" }
showValue x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment