我是OCaml的新手,我对.cma,.cmo和.cmx的文件感到困惑.有时我必须在编译命令中包含.cma文件,但有时我必须包含.cmo文件.
为什么图书馆会有这样的差异?它是C++中与库相同的概念并包含路径吗?
示例:ocamlc -o executable str.cma extstring.cmo mycode.ml
谢谢
嗨我一直在互联网上查找在OCaml中实现"字符串是否以某些文本结尾"的好方法,我发现在OCaml中操作字符串并不像我预期的那样与其他编程语言如Java相比. .
这是我的OCaml代码,使用Str.regexp来检查文件名是否以" .ml " 结尾,以查看它是否是OCaml脚本文件.它没有像我预期的那样工作:
let r = Str.regexp "*\\.ml" in
if (Str.string_match r file 0)
then
let _ = print_endline ("Read file: "^full_path) in
readFile full_path
else
print_endline (full_path^" is not an OCaml file")
Run Code Online (Sandbox Code Playgroud)
请注意,readFile是我自己编写的函数,用于从构造的full_path 读取文件.我总是在输出中得到结果,比如
./utilities/dict.ml is not an OCaml file
./utilities/dict.mli is not an OCaml file
./utilities/error.ml is not an OCaml file
./utilities/error.mli is not an OCaml file
Run Code Online (Sandbox Code Playgroud)
我在OCaml中的正则表达式有什么问题,是否有更好/更简单的代码来检查字符串?