Created
May 3, 2016 01:32
-
-
Save dreadedsoftware/06422e4f811876eb1d71c92cbca49754 to your computer and use it in GitHub Desktop.
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
module PatternMatch | |
type Type = | |
|Something of string * int | |
|Nothing | |
type Case = | |
|CaseA of a:string * b:int | |
|CaseB of a:string * b:double | |
let (|A|B|C|NOPE|) (input:char) = | |
match input with | |
|'A' -> A | |
|'B' -> B | |
|'C' -> C | |
|_ -> NOPE | |
let check() = | |
let rand = System.Random() | |
let item = rand.NextDouble() | |
let du = | |
match item with | |
|under when 0.5 < under -> Nothing | |
|over -> | |
Something(rand.Next().ToString(), rand.Next()) | |
let result = | |
match du with | |
|Something(s, i) -> s + i.ToString() | |
|Nothing -> "Nothing" | |
printfn "%A" result | |
let cc = | |
match item with | |
|under when 0.5 < under -> CaseA("", 0) | |
|over -> CaseB(over.ToString(), rand.NextDouble()) | |
let result2 = | |
match cc with | |
|CaseA("", 0) -> "Nothing" | |
|CaseB(a, b) -> a + " " + b.ToString() | |
|_ -> "Should not happen" | |
printfn "%A" result2 | |
let toThree = rand.Next(4) | |
let myChar = | |
match toThree with | |
|1 -> 'A' | |
|2 -> 'B' | |
|3 -> 'C' | |
|_ -> '-' | |
let result3 = | |
match myChar with | |
|A -> "Got A" | |
|B -> "B is here" | |
|C -> "And C wins" | |
|NOPE -> "Nothing" | |
printfn "%s" result3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment