Created
November 19, 2010 20:08
-
-
Save bennage/707069 to your computer and use it in GitHub Desktop.
a simple example of pattern matching 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
type Shape = | |
| Circle of float | |
| Rectangle of double*double | |
| EquilateralTriangle of double | |
let pi = 3.141592654 | |
let area shape = | |
match shape with | |
| Circle r -> r*r*pi | |
| Rectangle (h,w) -> h*w | |
| EquilateralTriangle side -> (sqrt 3.0)/4.0*side*side | |
let circle = Circle(15.0) | |
printfn "The area is %f" (area circle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment