-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Hi,
I am building an integration for frege here: https://github.com/invesdwin/invesdwin-scripting/tree/main/invesdwin-scripting-parent/invesdwin-scripting-haskell/invesdwin-scripting-haskell-runtime-frege/src/main/java/de/invesdwin/scripting/haskell/runtime/frege
The current integration works by running the FregeREPL in a separate process and communicating with it to provide Frege scripting integration from Java. This is because I could not figure out how to parse, eval, then extract results from the Frege API in Java because of all those complex generated java classes. Some old example I found somewhere to extract some results was outdated and did not work anymore. So the REPL it is.
Currently I am working on bidirectional communication between Java <-> Frege (file based because I can make this functional easily without global variables for a socket connection) . For that one can call something like callback ["someJavaFunctionStr" param1 param2 ... paramN]
inside a Frege script. Java then produces another Frege expression that is then supposed to be parsed by Frege and evaluated. Though I did not find a way to call eval "someExpressionStr"
inside the repl from within a function? I need something like the hint interpreter: https://stackoverflow.com/questions/2141148/best-way-to-call-haskell-functions-from-within-java/2144410#2144410 (though not yet tested for the GHCI integration). Maybe one can just import the FregeRepl and call eval to parse and execute a string?
print console (cmd@(Eval line)) (CodeInfo sourceRepr g msgs) env = case sourceRepr of |
Another option would be to return a json string from java to frege with additional type information to convert the values into frege values/lists/matrices based on the type. Though with that one would lose the capability to return arbitrary expressions from callback functions (which could be simulated though by running a second frege repl). Though this would be the most unnecessary complex and convoluted way to do this. No other language required workarounds like this (already done in the same repo for julia, python, R, matlab, ...).