Replies: 3 comments 2 replies
-
@mentorj can you post your code and build.mill file here? That will make it easier to spot ant issues |
Beta Was this translation helpful? Give feedback.
-
Hi, build.sc import mill._, scalalib._
object factorialscala extends ScalaModule {
def scalaVersion = "3.7.1"
}
object factorialjava extends JavaModule {
def mvnDeps = Seq(
mvn"io.vavr:vavr:0.10.4"
)
def moduleDeps = Seq(factorialscala)
}
object mainscala extends ScalaModule{
def scalaVersion = "3.7.1"
def moduleDeps = Seq(factorialscala)
} The Scala for factorial with TCO in module factorialscala package factorial;
import annotation.tailrec
object Factorial{
def factorial(x:Int): BigInt = {
@tailrec def loop(x: Int, acc: BigInt= 1): BigInt = {
if (x<=1) acc
else loop(x-1, x*acc)
}
loop(x)
}
} Java code wrapping Scala factorial in the factorialjava module import io.vavr.Function1;
import java.math.BigInteger;
class FactorialMemoized{
private static Function1<Integer,Long> factorialScala=Function1.of(factorial.Factorial.factorial);
private static Function1<Integer,Long> factorialMemoized = factorialScala.memoized();
public static Long runFactorial(Integer n){
return factorialMemoized.apply(n);
}
} Trying to compile whole project gives: > mill _.compile
No mill version specified.
You should provide a version via a '//| mill-version: ' comment or a '.mill-version' file.
Using mill version 1.0.3
[121/121] factorialjava.compile
[121] [info] compiling 1 Java source to /home/deadbrain/IdeaProjects/millFactorialMemoization/out/factorialjava/compile.dest/classes ...
[121] [error] /home/deadbrain/IdeaProjects/millFactorialMemoization/factorialjava/src/FactorialMemoized.java:5:89: cannot find symbol
[121] [error] symbol: variable factorial
[121] [error] location: class factorial.Factorial
[121] [error] factorial.Factorial.factorial
[121] [error] ^
[121/121, 1 failed] ======================== _.compile ========================
1 tasks failed
factorialjava.compile javac returned non-zero exit code
factorial Scala code works nice as stated by the third module > mill mainscala.run
No mill version specified.
You should provide a version via a '//| mill-version: ' comment or a '.mill-version' file.
Using mill version 1.0.3
[119/119] mainscala.run
[119] 30414093201713378043612608166064768844377641568960512000000000000
[119/119] =========================== mainscala.run ===========================
Now you have the complete vision... |
Beta Was this translation helpful? Give feedback.
-
Problem solved, not a Mill problem.I was stupid... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I am struggling with a quite simple Java/Scala project. Do you have any sample of such project ?
In one module I have a scala module with a factorial method living inside one object. Dead easy it compiles and runs fine
In one Java module I have a quite simple code getting the factorial method and memoizing this function.
The problem is that the factorial function from my Scala module is not found at compile time.
Using this function in another Scala module works fine of course.
Is it a mill problem ( possible I am quite new) or a Scala problem (it is the first time I try to invoke Scala code from Java).
Thanks for your help
Jerome
Beta Was this translation helpful? Give feedback.
All reactions