I'm trying out frege, and I'm struggling to try to use some native Java libraries.
I'm trying it out with the leiningen plugin, and Joda time. Apparently the lein plugin doesn't take care of correctly seeting the classpath for fregec, or maybe it's related to this difference:
java -jar ~/Downloads/frege3.22.524-gcc99d7e.jar -fp ~/.m2/repository/joda-time/joda-time/2.7/joda-time-2.7.jar src/Hello.fr
Will be able to find Joda, as expected, while
java -cp ~/.m2/repository/joda-time/joda-time/2.7/joda-time-2.7.jar -jar ~/Downloads/frege3.22.524-gcc99d7e.jar src/Hello.fr
will fail with
`org.joda.time.Years` is not a known java class
This shouldn't happen since, according to the wiki
The current class path of the running JVM plus the target directory are always on the class path.
Still, even after manually setting the -fp
, this code fails to compile:
module Hello where
data JodaYears = native org.joda.time.Years where
pure native years :: Int -> JodaYears
pure native getYears org.joda.time.Years.getYears :: JodaYears -> Int
-- ^ I tried both with and without this
The error is
Instance method or getter must be applied to java reference type.
But the only instance method that I'm using (getYears), takes the reference type as input (JodaYears
)... I even tried with org.joda.time.Years
, but the compilation still fails
Thanks to anyone who might shed some light on this
Brief answer, since using mobile.
You can't invoke Java with both -cp and -jar
Obviously, the class path is ignored in this case. You can try giving both jars in the -cp but then you also need to say what class to run. The frege compiler is frege.compiler.Main
Concerning the other error I think is related to "years" which is taken as instance method because of the simple name. Whereas the other method is taken as class method because of the qualified name.
The rules for defining native function foo are thus:
[pure] native foo XXX :: frege type