OCaml 中的正则表达式
我想在 OCaml 中使用regexps,并且 Str
模块似乎提供了这些功能。
所以我尝试了一个简单的程序:
open Str
let regx = regexp "."
但它给了我以下错误
文件“lol.ml”,第 1 行,字符 0-1: 错误:链接 lol.cmo 时出错: 引用未定义的全局“Str”
就好像模块不存在一样,但如果我删除 open Str
,它会说 regexp
是一个未绑定的值。
我不明白它是什么类型的问题, Str
应该是一个标准模块(根据 http://caml.inria.fr/pub/docs/old-311/libref/Str.html)所以我一无所知..唯一我认为签名(mli
)存在,但实现(ml
)不存在。
我正在根据 ocaml
工具运行 Objective Caml version 3.11.0
。
谁能帮我解决这个问题吗? 提前致谢
I want to use regexps in OCaml and it seems that Str
module provides these functionalities.
So I tried with a simple program:
open Str
let regx = regexp "."
but it gives me the following error
File "lol.ml", line 1, characters 0-1:
Error: Error while linking lol.cmo:
Reference to undefined global `Str'
As if module is not present but if I remove open Str
it says that regexp
is an unbound value.
I don't get what kind of issue it is, Str
should be a standard module (according to http://caml.inria.fr/pub/docs/old-311/libref/Str.html) so I'm clueless.. the only think I thought is that signature (mli
) is present but implementation (ml
) is not.
I'm running Objective Caml version 3.11.0
according to ocaml
tool.
Can anyone help me figuring this out?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自手册:
From the manual:
则可以输入
或者,如果您在解释器中执行此操作,
Or you can put
if you are doing it in the interpreter
作为
Str
模块的替代方案,还有Re2
。opam install re2
安装它使用
your_file.ml
中的模块,如下所示:使用
ocamlbuild -use-ocamlfind -package re2 -package core -tag thread your_file.byte 进行编译
As an alternative to the
Str
module there's alsoRe2
.opam install re2
Use the module in
your_file.ml
like this:Compile with
ocamlbuild -use-ocamlfind -package re2 -package core -tag thread your_file.byte