gpt4 book ai didi

haskell - Eta 可以与 Java 和/或 Kotlin 互操作吗?

转载 作者:行者123 更新时间:2023-12-02 12:02:26 24 4
gpt4 key购买 nike

我一直在学习 Haskell,但在日常工作中我正在编写 Kotlin/Java。

我遇到过 Eta ( https://eta-lang.org/ ),这是一种 Haskell 方言,可以编译为 Java 字节代码并在 JVM 上运行。在网站上它指出它有:

Robust Interoperability

Eta has a strongly-typed Foreign Function Interface (FFI) that allows you to safely interoperate with Java.

但页面下方有一个“即将推出”部分,其中列出了互操作性。所以我的问题是,在我开始设置开发环境的麻烦之前:

官方支持吗?

最佳答案

“即将推出”的是“绑定(bind)生成器”。 Eta has implemented syntax对于 Java 互操作,但您需要为要调用的每个 Java 实体显式编写外部声明。例如。如链接示例中所示,类似的类

public class Counter {
private int counter = 0;
private final int max;
public Counter(int max) { this.max = max; }
public int postIncrement() { return max == counter ? counter : counter++; }
}

需要阻止外国进口

data Counter = Counter @example.Counter deriving Class
foreign import java unsafe "@new" newCounter :: Int -> Java a Counter
foreign import java unsafe "postIncrement" postIncrement :: Java Counter Int

正如您可能猜到的那样,最好自动生成它。完成这一代的计划是 WIP,而不是 FFI 本身。

关于haskell - Eta 可以与 Java 和/或 Kotlin 互操作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59795708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com