有哪些 OCaml 库可用于惰性列表处理?

发布于 2024-08-04 12:29:37 字数 403 浏览 7 评论 0原文

有哪些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘亓 2024-08-11 12:29:37

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 .

恋你朝朝暮暮 2024-08-11 12:29:37

另外,我的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文