Open Jyothsnasrinivas opened 6 years ago
I'm new to this but doesnt the fact that java classes contain state make this impossible? I think this would naively convert the code , but it is quite possible that any of the calls have side effects that could change the state of the object invisibly. Then factor things in like AOP or spring dynamic proxies and I would suggest that the translation should be only one way.
I'm new to this but doesnt the fact that java classes contain state make this impossible?
Oh, but the proposal is to just 1-to-1 convert imperative calls to Java monad calls, not try to convert java code to idiomatic haskell.
Then factor things in like AOP or spring dynamic proxies and I would suggest that the translation should be only one way.
Bytecode-level AOP will probably still work, as the java method calls remain there.
I feel like you could do this with grammars / parsing. I'm not super familiar with traditional grammar parsers like ANTLR, I typically float around prolog and DCG's a bit more, but with prolog you can pretty easily equate two parts of two different AST's and convert between two gramar-based langs that way.
Recently, I've been trying to implement Eta examples for various Java frameworks. And I found a repetitive pattern while converting the Java examples to Eta. I was wondering if we could automate this with a tool to make it easy to copy paste Java code samples and directly convert it to Eta code.
Let's see a simple Web Server in Java and Eta:
When implemented in Java
When implemented in Eta
From the above example we can infer the following:
Java's variable declaration converts to the bind in the
Java
monad.For Example:
Java
Eta
Java's instance method call can be done in Eta via
<.>
operator.For Example:
Java
Eta
More points to be added as we encounter more similarities
A good starting point can be to take a look at Java to Kotlin Converter which has done a great job and many companies are using it to migrate their Java codebase to Kotlin.
This might be tricky for Data Processing/Streaming frameworks where the APIs are tricky with Generic Subtyping, F-Bounded Polymorphism, etc, but it would be great to push this as far as we can.