user3581210
user3581210

Reputation: 1

Syntax Error OCaml

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

Answers (1)

ivg
ivg

Reputation: 35210

val is a reserved word, you can't use it

Upvotes: 2

Related Questions