Created
March 19, 2018 11:26
-
-
Save tugberkugurlu/42d4f0562545cb6d9f69fb1371181cd0 to your computer and use it in GitHub Desktop.
F# pattern matching sample
This file contains 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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: