Skip to content

Instantly share code, notes, and snippets.

@andybrackley
Created February 23, 2014 20:12
Show Gist options
  • Save andybrackley/9176574 to your computer and use it in GitHub Desktop.
Save andybrackley/9176574 to your computer and use it in GitHub Desktop.
(* Duck Typing *)
let inline flyAndWalk arg =
let flying = ( ^a : (member Fly : unit -> string) arg)
let walking = ( ^a : (member Walk : unit -> string) arg)
(flying, walking)
type Duck() =
member this.Swim() = "paddling"
member this.Fly() = "flapping"
member this.Walk() = "waddling"
type Eagle() =
member this.Fly() = "soaring"
member this.Walk() = "creeping"
let (eFly, eWalk) = flyAndWalk (new Eagle())
let (dFly, dWalk) = flyAndWalk (new Duck())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment