How to build a map of the frequency with which characters occur in a file in OCaml?

How to build a map of the frequency with which characters occur in a file in OCaml?



AAAAA BB C

{ ' ' -> 2, 'A' -> 5, 'B' -> 2, 'C' -> 1 }

let usage = "usage: " ^ Sys.argv.(0) ^ " [OPTION]... [FILE]..."
let file = ref ""
let speclist = [
  ("-z", Arg.String (fun c -> file := c), " compress [FILE]");
  ("-d", Arg.String (fun d -> file := d), " decompress [FILE]");
]

let build_freq_map f =
  let channel = open_in f in
  function x ->
    input_byte channel

let () =
  Arg.parse
    speclist
    (fun x -> raise (Arg.Bad ("Bad argument: " ^ x)))
    usage;

  build_freq_map !file;

File "main.ml", line 19, characters 1-22:
Error: This expression has type 'a -> int
       but an expression was expected of type unit

Comments

Popular posts from this blog

How to change this to <%Html.ActionLink%> in my asp.net mvc application ?