Last active
December 20, 2015 18:19
-
-
Save joseph-montanez/6175120 to your computer and use it in GitHub Desktop.
get the same label from different types of records
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
Mechanical Pencil's diametric rating: 1.500000 | |
Black Pen's diametric rating: 2.000000 |
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
type Colors = Black | Red | Blue | |
type Pen = { | |
Diameter: float | |
Rating: int | |
InkColor: Colors | |
} | |
type Pencil = { | |
Diameter: float | |
Hardness: int | |
Blackness: int | |
Rating: int | |
} | |
let inline getDiametricRating ( | |
t:^q when | |
^q : (member Diameter:float) and | |
^q : (member Rating:int) | |
) = | |
let diameter = (^q : (member Diameter:float) t) | |
let rating = float(^q : (member Rating:int) t) | |
diameter * rating | |
let mechanical_pencil = { | |
Diameter = 0.5 | |
Hardness = 1 | |
Blackness = 2 | |
Rating = 3 | |
} | |
let black_pen = { | |
Diameter = 1.0 | |
Rating = 2 | |
InkColor = Red | |
} | |
printfn "Mechanical Pencil's diametric rating: %f" (getDiametricRating mechanical_pencil) | |
printfn "Black Pen's diametric rating: %f" (getDiametricRating black_pen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment