java - 从 Frege 调用 native Java 构造函数

标签 java jvm native frege

你知道在哪里可以找到有关 Frege 的 Java 绑定(bind)的文档吗?来自 Haskell,我发现 Frege 最有趣的方面。 documentation不幸的是我发现并没有详细说明。

这是我的测试示例。基本上,我想翻译以下 Java 代码:

BigDecimal x = BigDecimal.valueOf(7);
BogDecimal y = new BigDecimal("5.13");
System.out.println(x.add(y));

这是我当前的弗雷格代码:

module Main where

data JBigDecimal s = pure native java.math.BigDecimal
  where
  pure native jAdd add :: JBigDecimal RealWorld -> JBigDecimal RealWorld -> JBigDecimal RealWorld
  pure native jShow toString :: JBigDecimal RealWorld -> String

pure native jBigDecimalI java.math.BigDecimal.valueOf :: Int -> JBigDecimal RealWorld

-- ERROR: Here, I don't know what I should write.
-- I want to bind to the BigDecimal(String) constructor.
-- I tried several versions but none of them was successful, e.g.:
pure native jBigDecimalS java.math.BigDecimal.BigDecimal :: String -> JBigDecimal RealWorld

main :: [String] -> IO ()
main args = let x = jBigDecimalI 7
                y = jBigDecimalS "5.13"
                z = JBigDecimal.jAdd x y
            in printStrLn $ (JBigDecimal.jShow z)
-- (BTW, why `printStrLn` and not `putStrLn` as it is called in Haskell?)

为了完整起见,错误消息是:

calling: javac -cp fregec-3.21.jar:. -d . -encoding UTF-8 ./Main.java 
./Main.java:258: error: cannot find symbol
        return java.math.BigDecimal.BigDecimal(
                               ^
  symbol:   method BigDecimal(String)
  location: class BigDecimal
1 error
E frege-repl/example.fr:15: java compiler errors are most likely caused by
    erronous native definitions

最佳答案

我找到了。构造函数被调用new:

pure native jBigDecimalS new :: String -> JBigDecimal RealWorld

关于java - 从 Frege 调用 native Java 构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15013824/

相关文章:

java - java中main方法中声明的变量

java - 关于java中的双键并发hashmap

java - Android工作室: dont work JsonArrayRequest

java - 寻求有关 JVM 随机崩溃的帮助

multithreading - native 互斥体实现

Android:如何从 native 代码获取设备 DPI

java - 如何在Java中反转字符串

java - 字节缓冲区内存分配

java - 如何在没有引用的情况下访问 Java 堆对象?

xml - 有没有原生支持 xml 的编程语言?