Created
August 26, 2011 11:42
-
-
Save forki/1173248 to your computer and use it in GitHub Desktop.
F# problem with 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
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