Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created March 19, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/42d4f0562545cb6d9f69fb1371181cd0 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/42d4f0562545cb6d9f69fb1371181cd0 to your computer and use it in GitHub Desktop.
F# pattern matching sample
// Learn more about F# at http://fsharp.org
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
[<EntryPoint>]
let main argv =
let foo = getShapeHeight rect
printfn "Hello!"
0 // return an integer exit code
@tugberkugurlu
Copy link
Author

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:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment