Created
June 21, 2012 09:32
-
-
Save forki/2964839 to your computer and use it in GitHub Desktop.
Static duck typing
This file contains 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
let inline speak (a: ^a) = | |
let x = (^a : (member Name: string) (a)) | |
printfn "I'm %s" x | |
let y = (^a : (member talk: unit -> string) (a)) | |
printfn "I say %s" y | |
type Duck = | |
{ Name : string } | |
member x.talk() = "quackity quack" | |
type Dog(name) = | |
member x.Name = name | |
member x.talk() = "arrrr" | |
let x = { Name = "Donald" } | |
let y = new Dog("Pluto") | |
speak x | |
speak y | |
System.Console.ReadKey() |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment