Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
F# pattern matching sample
// Learn more about F# at
type Shape =
| Rectangle of width : float * length : float
| Circle of radius : float
| Prism of width : float * float * height : float
let rect = Rectangle(length = 1.3, width = 10.0)
let circ = Circle(1.0)
let getShapeHeight (shape: Shape) :float =
match shape with
| Rectangle(width = h) -> h
| Circle(radius = r) -> 2. * r
let main argv =
let foo = getShapeHeight rect
printfn "Hello!"
0 // return an integer exit code

This comment has been minimized.

Copy link
Owner Author

commented Mar 19, 2018

Remove line 6 above and try to compile this. It will be happy. Add the line 6 back and compile, you will get a warning like below:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.