Skip to content

Instantly share code, notes, and snippets.

@sayurin
Created August 30, 2016 22:15
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 sayurin/b7953083a207debdf7bdce64cee6463f to your computer and use it in GitHub Desktop.
Save sayurin/b7953083a207debdf7bdce64cee6463f to your computer and use it in GitHub Desktop.
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