1 people like it.

C# 7.0 tally

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
/// todo: replace mutable by array.reduce
let rec tally (values :obj array) =
    let mutable r = 0,0
    let add = fun s c -> r <- s + fst r, c + snd r
    values |> Array.iter(function
        | :? int as i -> add i 1
        | :? array<obj> as a when a.Length > 0 ->
            tally(a) ||> add
        | _ -> printfn "f# can't leak by accident!")
    r
val tally : values:obj array -> int * int

Full name: Script.tally


 todo: replace mutable by array.reduce
val values : obj array
type obj = System.Object

Full name: Microsoft.FSharp.Core.obj
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>
val mutable r : int * int
val add : (int -> int -> unit)
val s : int
val c : int
val fst : tuple:('T1 * 'T2) -> 'T1

Full name: Microsoft.FSharp.Core.Operators.fst
val snd : tuple:('T1 * 'T2) -> 'T2

Full name: Microsoft.FSharp.Core.Operators.snd
module Array

from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> array:'T [] -> unit

Full name: Microsoft.FSharp.Collections.Array.iter
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val i : int
val a : obj array
property System.Array.Length: int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/7QE
Posted:7 years ago
Author:
Tags: