Nice F# List.fold example

Got this example from here.

open System
open System.Threading
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open System.IO
open Microsoft.VisualBasic.FileIO

let main argv =
   let data = [(Cats,4);

   let count = List.fold (fun acc (nm,x) acc+x) 0 data
   printfn "Total number of animals: %d" count

Even though I’ve used map and other functions in Clojure, I’ve forgotten the basics of an inline function. The value of 0 is assigned to nm, and x takes on the first row of data.



Leave a comment

Filed under F#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s