OCaml 和 F# 之间的代码兼容性

发布于 2024-10-03 19:12:38 字数 151 浏览 0 评论 0原文

大家好,

我正在 OCaml 中开发一个小型爱好项目。我想知道将其迁移到 F# 有多容易。我知道 F# 具有 OCaml 没有的一些功能,但我希望我的 OCaml 代码不需要太多努力即可移植。我不一定要迁移,我想在两个平台上保留/发展。

提前致谢, 迈克尔

Good day all,

I am developing a small hobby project in OCaml. I was wondering how easy it would be to migrate it to F#. I know that F# has some features that OCaml doesn't, but I was hoping that my OCaml code would require little effort to port. I don't necessarily want to migrate, I want to retain / develop on both platforms.

Thanks in advance,
Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

高冷爸爸 2024-10-10 19:12:38

对我来说,编写交叉编译代码似乎是一个痛苦的世界。据我所知,Coherent PDF 的 John Whitington 是唯一一个真正尝试过这样做的人。

我已经将大量 OCaml 代码翻译为 F#(可能比世界上任何其他人都多),主要问题是 #light 语法、任何重要 OCaml 功能(对象、多态变体)的使用、高阶模块、标记和可选参数等)、库(例如 lablgl、lablgtk、ocamlgraph、lazyness)、宏(解析、流、模式匹配扩展)以及基本语法(例如数组索引)的更改。例如,我只是尝试移植 Almabench 基准测试 从 OCaml 到 F#,花了几个小时,因为我最终不得不将每个 a.[i] 重写为 a由于 F# 编译器中存在大量错误,(i) 需要手动进行:其 OCaml 兼容模式非常脆弱。

因此,我建议您在两种语言之间进行选择,而不是尝试交叉编译。

Writing cross-compiling code looks like a world of pain to me. John Whitington of Coherent PDF is the only person I know of who has tried to do this to any real degree.

I have translated a lot of OCaml code to F# (probably more than anyone else in the world) and the main problems are #light syntax, the use of any non-trivial OCaml features (objects, polymorphic variants, higher-order modules, labelled and optional arguments and so on), libraries (e.g. lablgl, lablgtk, ocamlgraph, laziness), macros (parsing, streams, pattern matching extensions) and changes in basic syntax such as array indexing. For example, I just tried to port the Almabench benchmark from OCaml to F# and it took several hours because I ended up by having to rewrite every a.[i] to an a.(i) by hand due to a multitude of bugs in the F# compiler: its OCaml compatibility mode is quite fragile.

So I would advise you to choose between the languages rather than trying to cross-compile.

扭转时空 2024-10-10 19:12:38

您应该阅读规范的最后部分

ML 兼容性功能

,并确保从 PowerPack 获取 FSharp.PowerPack.Compatibility.dll各种兼容库。

You should read the final portion of the spec

Features for ML Compatibility

and be sure to grab FSharp.PowerPack.Compatibility.dll from the PowerPack for various compat libraries.

森林迷了鹿 2024-10-10 19:12:38

我还没有对 F# 进行任何 OCaml 移植,但我知道 F# 在设计时就考虑到了 OCaml 兼容性。据我所知,F# 主要是基本 OCaml 的超集。

它应该支持(且不限于)大多数 OCaml 关键字,并具有核心库(或 .Net 框架)中大多数标准函数的等效项。所以我猜想——至少对于业余爱好项目来说——移植实际上应该很容易。

不过,F# 没有 OCaml 的高级模块系统,因此您在实现函子等方面会遇到麻烦。

I haven't done any OCaml to F#-porting, but I know F# has been designed with OCaml compatibility in mind. As I know, F# is mostly a superset of basic OCaml.

It should support (and without #light be limited to) most OCaml keywords and have equivalents of most standard functions in the core libraries (or in the .Net framework). So I'd guess that - at least for hobby projects - porting should be actually easy.

F# doesn't have OCaml's advanced module system though, so you'll have trouble with implementing e.g. functors.

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