Created
June 8, 2011 15:18
-
-
Save mattpodwysocki/1014623 to your computer and use it in GitHub Desktop.
Generic Restrictions
This file contains hidden or 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 name (x : ^T) = (^T : (member Name : string) (x)) | |
let inline age (x : ^T) = (^T : (member Age : int) (x)) | |
let inline nameAndAge x = (name x, age x) | |
type Person(name : string, age : int) = | |
member __.Name = name | |
member __.Age = age | |
type Employee(name : string, age : int, employeeId : string) = | |
member __.Name = name | |
member __.Age = age | |
member __.EmployeeId = employeeId | |
let person = Person("Matt", 5) | |
let employee = Employee("Matt", 5, "12345") | |
name person // prints Matt | |
age person // prints 5 | |
nameAndAge person // prints ("Matt", 5) | |
name employee // prints Matt | |
age employee // prints 5 | |
nameAndAge employee // prints ("Matt", 5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment