Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Last active December 20, 2015 18:19
Show Gist options
  • Save joseph-montanez/6175120 to your computer and use it in GitHub Desktop.
Save joseph-montanez/6175120 to your computer and use it in GitHub Desktop.
get the same label from different types of records
Mechanical Pencil's diametric rating: 1.500000
Black Pen's diametric rating: 2.000000
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