开始OCaml开发并面临一些问题
我正在阅读并完成一些练习 我按照书中的说明编写了这个程序:开始OCaml开发并面临一些问题,ocaml,Ocaml,我正在阅读并完成一些练习 我按照书中的说明编写了这个程序: open Core.Std let build_counts() = In_channel.fold_lines stdin ~init:[] ~f:(fun counts line -> let count = match List.Assoc.find counts line with | None -> 0 | So
open Core.Std
let build_counts() =
In_channel.fold_lines stdin ~init:[] ~f:(fun counts line ->
let count =
match List.Assoc.find counts line with
| None -> 0
| Some x -> x
in
List.Assoc.add counts line (count + 1)
)
let () =
build_counts()
|> List.sort ~cmp:(fun (_, x) (_, y) -> Int.descending x y)
|> (fun l -> List.take l 10)
|> List.iter ~f: (fun (line, count) -> printf "%3d: %s\n" count line)
现在这几个问题已经解决了
sudoopaminstallcore
,然后运行了corebuildtest.ml
。命令没有抛出任何错误。。。但他什么也没做。它没有生成任何二进制文件ocamlfind ocamlc-linkpkg-thread-package core Test.ml-o Test.byte
这产生了一个Test.byte文件,我可以运行它,但问题是我可以继续输入行,但我无法让程序产生任何结果,因为它处于接受控制台输入的无限循环中
如果我按下cntl+c,那么整个程序将终止。。。再次没有评估corebuild Test.ml
,现在会收到一条错误消息SANITIZE: a total of 2 files that should probably not be in your source tree
has been found. A script shell file
"/home/abhishek/Documents/_build/sanitize.sh" is being created. Check this
script and run it to remove unwanted files or use other options (such as
defining hygiene exceptions or using the -no-hygiene option).
IMPORTANT: I cannot work with leftover compiled files.
ERROR: Leftover OCaml compilation files:
File Test.cmo in . has suffix .cmo
File Test.cmi in . has suffix .cmi
Exiting due to hygiene violations.
所以事情并不像书中说的那样发展。我在使用OCaml工具和语言时遇到了困难。任何帮助都将不胜感激。第一个问题我无能为力 对于第二个问题,假设您使用的是类似于Unix的系统:输入^D(control D) 结束您的输入。您还可以创建文件并从该文件重定向:
$ Test.byte < my-input-file
$Test.byte<我的输入文件
请注意,这不是OCaml语言问题。它是关于在计算机上处理文件的
您的系统(或者可能与命令行环境有关)
对于第三个问题,请删除.cmo和.cmi文件并重试,如消息所示。关于第一个问题,ocamlbuild(corebuild是包装器)通过让您指定所需的结果来工作。所以你可能有一个
corebuild test.byte
corebuild test.native
corebuild test.cmo
其中
.byte
和.native
将指定字节编译和本机编译的可执行文件,.cmo
将指定仅编译文件(如果编译成功,将在\u build
下)。我的答案可能会晚一点,但这对我来说是可行的。我得到了与粘贴相同的输出,我运行文件/home/abhishek/Documents/_build/sanitize.sh
删除所有“不需要的文件”,然后执行corebuild freq.byte
,效果很好。在您的情况下,您应该运行corebuild test.byte
,我认为。尝试corebuild test.byte
(字节)或corebuild test.native
执行本机代码。是的,我还建议您使用corebuild