Functional Programming & Proofs

back

Other collections with illustration

FP is usefull for Data Processing and F# integrates all fundamental datatypes: sequences, sets, maps, etc.

  1. Statistics on texts: String
let text    = "hello world !";;
let letters = [ 'a' .. 'z' ] @ [ 'A' .. 'Z' ];;
let countL  = txt |> Seq.filter (fun l -> l='l') |> Seq.length ;;
let count letter = txt |> Seq.filter (fun l -> l=letter) |> Seq.length ;;
let stats   = letters |> List.map (fun l -> (l,count l));;
let simple  = stats |> List.filter (fun (l,c) -> c<>0 );;
let sort    = simple |> List.sortBy (fun (l,c) -> c);;