Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created February 24, 2009 23:27
Show Gist options
  • Select an option

  • Save DRMacIver/69872 to your computer and use it in GitHub Desktop.

Select an option

Save DRMacIver/69872 to your computer and use it in GitHub Desktop.
let sum = List.fold_left (fun s x -> s + x) 0
let split = Str.split (Str.regexp_string " ")
let each_line f =
let rec go () =
let _ = f (input_line stdin) in go ()
in try go() with End_of_file -> ()
let words = Hashtbl.create 8
let count x = try Hashtbl.find words x with Not_found -> 0
let inc x = Hashtbl.replace words x (count x + 1);;
each_line inc;
Hashtbl.iter (Printf.printf "%s: %d") words;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment