Skip to content

Instantly share code, notes, and snippets.

@bennage
Created November 19, 2010 20:08
Show Gist options
  • Save bennage/707069 to your computer and use it in GitHub Desktop.
Save bennage/707069 to your computer and use it in GitHub Desktop.
a simple example of pattern matching in F#
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