Skip to content

Instantly share code, notes, and snippets.

@forki
Created August 26, 2011 11:42
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 forki/1173248 to your computer and use it in GitHub Desktop.
Save forki/1173248 to your computer and use it in GitHub Desktop.
F# problem with duck typing
type A = { Age: int; Name: string }
type B = { name: string } with member this.Name = this.name
let inline name (x:^T) = (^T : (member Name : string) x)
let a = { Age = 29; Name = "Steffen" }
let b = { name = "Gary" }
printfn "%A" <| name a // doesn't work
printfn "%A" <| name b // works
// It would be even cooler if this property access helper would be created automatically.
// Even if this would break some old code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment