我开始在OCaml中编写此代码,以获取文件中每个字符的计数。
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;;
当我尝试使用
ocamlc -c
进行编译时,收到消息:Error: Syntax error:
最佳答案
val
是保留字,您不能使用它
关于syntax-error - 语法错误OCaml,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26868293/