Created
November 12, 2017 00:55
-
-
Save bryanhunter/41d5c46464320e15f5812fda9ee4e11f to your computer and use it in GitHub Desktop.
Union type with units of measure
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
module UnitsOfMeasure | |
[<Measure>] type cm | |
[<Measure>] type inch | |
type Shape<[<Measure>]'u> = | |
| Circle of float<'u> | |
| Square of float<'u> | |
| Triangle of float<'u> * float<'u> | |
| Rectangle of float<'u> * float<'u> | |
let GetArea shape = | |
match shape with | |
| Circle(radius) -> 3.14 * radius * radius | |
| Square(width) -> width * width | |
| Triangle(``base``, height) -> ``base`` * height / 2.0 | |
| Rectangle(width, height) -> width * height |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment