有哪些 OCaml 库可用于惰性列表处理?
有哪些 OCaml 库提供惰性列表处理?我正在寻找类似的东西:
type 'a lazy_list = (*'*)
| Nil
| Cons of 'a * 'a lazy_list lazy_t
let from f =
let rec gen n =
lazy
(
match f n with
| Some x ->
Cons (x, gen (n + 1))
| None ->
Nil
)
in
gen 0
与 Stream
类型和回溯 Camlp4 解析器的语法糖集成会很好。
What OCaml libraries are out there that provide lazy list handling? I am looking for something along these lines:
type 'a lazy_list = (*'*)
| Nil
| Cons of 'a * 'a lazy_list lazy_t
let from f =
let rec gen n =
lazy
(
match f n with
| Some x ->
Cons (x, gen (n + 1))
| None ->
Nil
)
in
gen 0
Integration with the Stream
type and syntactic sugar for backtracking Camlp4 parsers would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Ocaml 电池有一个惰性列表模块,查看
to_stream
函数。至于回溯,现在您有了 Stream.t ,您可以查看 camlp4 的流解析器。Ocaml Batteries has a lazy list module, check out the
to_stream
function. As for backtracking, you can look into camlp4's stream parsers now that you have a Stream.t .另外,我的 OCaml 网络应用程序环境 中有一个名为
Cf_seq
的惰性列表模块核心基础。事实上,我写了一整套函数式数据结构。这一切都可以在 2 条款 BSD 许可证下使用。享受。更新:代码已重命名为“Oni”,现在托管在位桶。您还可以使用 GODI 包。
Also, there is a lazy list module called
Cf_seq
in my OCaml Network Application Environment Core Foundation. In fact, I wrote a whole passle of functional data structures. It's all available under a 2-clause BSD license. Enjoy.Update: the code has been renamed "Oni" and it's now hosted at BitBucket. You can also use the GODI package for it.