Created
May 14, 2020 14:58
-
-
Save SchlenkR/c7fdcb51ed490671230bb8f5014ea4eb to your computer and use it in GitHub Desktop.
An F# record that implements an interface
This file contains hidden or 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
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