Created
August 30, 2016 22:15
-
-
Save sayurin/b7953083a207debdf7bdce64cee6463f 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 Program = | |
let rec Main args = | |
let numbers : obj[] = | |
[| 0b1; 0b10; ([| 0b100; 0b1000 |] : obj[]); // binary literals | |
0b10000; 0b100000 |] // digit separators: not supported | |
let sum, count = Tally(numbers) // deconstruction | |
printfn "Sum: %d, Count: %d" sum count | |
and Tally (values : obj[]) = // tuple types | |
let mutable r = 0, 0 // tuple literals | |
let Add s c = r <- fst r + s, snd r + c // local functions | |
for v in values do | |
match v with | |
| :? int as i -> // type patterns | |
Add i 1 | |
| :? (obj[]) as a when a.Length > 0 -> // case conditions | |
let t = Tally a | |
Add (fst t) (snd t) | |
| _ -> | |
assert false | |
r | |
Main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment