Reputation: 1
I started writing this in OCaml in order to get a count of each character in a file.
open Hashtbl;;
type 'a option = None | Some of 'a;;
let rec charCount fd ht =
let x =
try Some (input_char fd)
with End_of_file -> None
in
match x with
| Some c ->
let val =
try find (ht c)
with Not_found -> 0
in
replace ht c (val+1);
charCount fd ht
| None -> ();;
let ht = create 0;;
let loadHisto fn =
let fd = open_in fn
in
charCount fd ht;;
loadHisto "testfile";;
iter printf("%s => %s\n") ht;;
When I try to compile it with ocamlc -c
I get the message :
Error: Syntax error:
Upvotes: 0
Views: 918