Created
November 12, 2017 00:54
-
-
Save bryanhunter/006535aaf8862ba1d199a0b45f6f173e to your computer and use it in GitHub Desktop.
Shape union in F#
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
module UnionTypes | |
// Learn more about F# at http://fsharp.org | |
type Shape = | |
| Circle of float | |
| Square of float | |
| Triangle of float * float | |
| Rectangle of float * float | |
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