Tho*_*ook 6 haskell jvm functional-programming eta
我一直在学习 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.
Run Code Online (Sandbox Code Playgroud)
但在页面下方有一个“即将推出”部分,其中列出了互操作。所以我的问题,在我去设置一个开发环境的麻烦之前:
这是官方支持的吗?
“即将推出”的是“绑定生成器”。Eta 已经实现了 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++; }
}
Run Code Online (Sandbox Code Playgroud)
需要阻止外国进口
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
Run Code Online (Sandbox Code Playgroud)
正如您可能猜到的那样,最好自动生成它。实现这一代的计划是 WIP,而不是 FFI 本身。