First of all sorry for my English, and for the fact that I'm trying to learn Haskell
I would run Frege code (Haskell) calling from java, for almost all aspects I managed to make it all work as per instructions found on various sites ... but I still have a question about the following code, and sorry for the wordiness of the request ...
javaHelloTest.java
package local.java;
import java.io.PrintWriter;
import java.util.Arrays;
import frege.runtime.Runtime;
import frege.runtime.Runtime.*;
import frege.java.Util.TList;
import frege.prelude.PreludeArrays;
import frege.prelude.PreludeBase;
import frege.control.monad.State;
import frege.run7.*;
import local.frege.FregeHelloTest;
public class JavaHelloTest {
public static void main(String[] args) {
System.out.println("Hello World from Java code ... ");
System.out.println("========================");
System.out.println("callingMain0 ... ");
System.out.println("------------------------");
FregeHelloTest.callingMain0(Thunk.<PreludeBase.TList<String>>lazy(PreludeArrays.IListSource_JArray.<String>toList(args)));
System.out.println("========================");
System.out.println("callingMain1 ... ");
System.out.println("------------------------");
FregeHelloTest.callingMain1(Thunk. <PreludeBase.TList<String>>lazy(PreludeArrays.IListSource_JArray.<String>toList(args)));
System.out.println("========================");
System.out.println("callingMain2 ... ");
System.out.println("------------------------");
FregeHelloTest.callingMain2(Thunk. <PreludeBase.TList<String>>lazy(PreludeArrays.IListSource_JArray.<String>toList(args)));
System.out.println("========================");
}
}
fregeHelloTest.fr
module local.frege.FregeHelloTest where
import Prelude.PreludeBase as PreludeBase
main :: [String] -> IO ()
main args = println $ "Hello World from Frege code ..."
callingMain0 :: [String] -> ()
callingMain0 ss = PreludeBase.ST.performUnsafe(main ss)
callingMain1 :: [String] -> IO ()
callingMain1 ss = return ( PreludeBase.ST.performUnsafe(main ss) )
callingMain2 :: [String] -> ()
callingMain2 ss = PreludeBase.ST.run( return ( PreludeBase.ST.performUnsafe(main ss) ) )
fregeHelloTest.java (GENERATED from fregec)
{ ... omissis ... }
final public class FregeHelloTest {
final public static Func.U<RealWorld, Short> $main(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return PreludeBase.<Func.U<RealWorld, Short>, String/*<Character>*/>$(
new Func.U.D<String/*<Character>*/, Func.U<RealWorld, Short>>() {
public Lazy<Func.U<RealWorld, Short>> apply(final Lazy<String/*<Character>*/> η$7611) {
return Thunk.<Func.U<RealWorld, Short>>shared(
new Lazy.D<Func.U<RealWorld, Short>>() {
public Func.U<RealWorld, Short> call() {
return Prelude.<String/*<Character>*/>println(PreludeText.IShow_String.it, η$7611.call());
}
}
);
}
},
Thunk.<String/*<Character>*/>lazy("Hello World from Frege code ...")
).call();
}
final public static short callingMain2(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return (short)PreludeBase.TST.<Short>run(
PreludeMonad.IMonad_ST.<Object, Short>pure(
Thunk.<Short>nested(
new Lazy.D<Lazy<Short>>() {
public Lazy<Short> call() {
return PreludeBase.TST.<Short>performUnsafe(FregeHelloTest.$main(arg$1));
}
}
)
)
).call();
}
final public static Func.U<RealWorld, Short> callingMain1(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return PreludeMonad.IMonad_ST.<RealWorld, Short>pure(
Thunk.<Short>nested(
new Lazy.D<Lazy<Short>>() {
public Lazy<Short> call() {
return PreludeBase.TST.<Short>performUnsafe(FregeHelloTest.$main(arg$1));
}
}
)
);
}
final public static short callingMain0(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return (short)PreludeBase.TST.<Short>performUnsafe(FregeHelloTest.$main(arg$1)).call();
}
public static void main(final java.lang.String[] argv) { ... omissis ... }
}
Program output ... with entry point: local.java.JavaHelloTtest.main
------------------
Hello World from Java code ...
========================
callingMain0 ...
------------------------
Hello World from Frege code ...
========================
callingMain1 ...
------------------------
========================
callingMain2 ...
------------------------
Hello World from Frege code ...
========================
and after long (for me) survey I realized it is right that "CallingMain1" does not perform anything ... in fact, as you can see generated by the "callingMain2" needs a "run" ... but if I try to execute, with a "run", what comes back "callingMain1" IDE (Eclipse and then the compiler) tells me that the signature is incorrect, PreludeBase.TST.<Short>run is on "Object" and not on "RealWorld", in fact, the compiler in the case of "callingMain2" sets a "Object" and not a "RealWorld" to run callingMain2.
obviously (I think) the signature (Haskell) of "callingMain1" is correct ... and I think no one can touch ...
and now the question ... at this point I think, perhaps, it should be a function ... TST.runOnRealWorld allowing assessment IO () returned from yet "callingMain1"; however, as in the generation of "callingMain2" I clearly see that the operation is changed on-the-fly on "Object" I have to assume that this function does not exist ...
this is wanted or just need to add a "run" method that allows java to evaluate the output of "callingMain1" ?
or, more likely, I understood very little ... Thanks a lot in advance ...