OOP in F#

Combining functional and object-oriented styles

Classes

type Person(name: string, age: int) =
    member this.Name = name
    member this.Age = age
    member this.Greet() =
        printfn "Hello, my name is %s" this.Name

let john = Person("John", 30)
john.Greet()

Interfaces

type IShape =
    abstract Area: float
    abstract Perimeter: float

type Circle(radius: float) =
    interface IShape with
        member this.Area = Math.PI * radius * radius
        member this.Perimeter = 2.0 * Math.PI * radius

Interop with C#

// Using C# libraries
open System.Windows.Forms

let form = new Form(Text="Hello World")
form.ShowDialog() |> ignore