Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created August 25, 2014 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/41fad25b94a8161e6cab to your computer and use it in GitHub Desktop.
Save liammclennan/41fad25b94a8161e6cab to your computer and use it in GitHub Desktop.
f# interfaces
module Library1
open NUnit.Framework
open FsUnit
type IHaveAnAge =
abstract age: int
type Person =
{ name: string; age: int }
interface IHaveAnAge with
member x.age = x.age
type Tree =
{ species: string; rings: int }
interface IHaveAnAge with
member x.age = x.rings / 2
let printAge (t:IHaveAnAge) =
t.age |> printfn "%A"
[<TestFixture>]
type Class1() =
[<Test>]
member this.X ()=
{ name = "Liam"; age = 31 } |> printAge
{ species = "Pine"; rings = 88 } |> printAge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment