3

I have nice OCaml code (30000 lines apox). I want to port it to Java. So Is there any free OCaml to Java translator?

I need it as my own project is in Java and i'm also comfortable with java, but in project I've to use the OCaml code, i don't want to reinvent the wheel ... I just want to modify that code(OCaml) and use it..

I've seen the OCaml to Java , but it just make possible to call ocaml code from Java code that is good but i need complete translation.. A source code(OCaml) to source code(Java) compiler..

Imran
  • 5,376
  • 2
  • 26
  • 45
  • 2
    OCaml is a functional language with a completely different set of idioms from the object oriented Java. It amazes me to see that you think automated translation may even be possible. If you just want to target the JVM, it may be easier to rewrite your code to Scala: It is both object oriented and functional, so you'll have to make less architectural changes. – amon Sep 04 '13 at 17:58
  • 2
    Difficult this would be. But maybe now that Java has some kind of lambda it would be a bit easier - after all, we do have js_of_ocaml which compiles OCaml to Javascript. – aneccodeal Sep 04 '13 at 19:09
  • 2
    OCaml byte code to c translation: http://oud.ocaml.org/2012/abstracts/oud2012-final10.pdf – zakki Sep 05 '13 at 08:30
  • 1
    @amon : OCaml is object-oriented as well. There are many similarities between these two languages. As far as I can see, with the imminent coming of Java 8, OCaml and Java are getting more similar. – Chthonic Project Dec 06 '13 at 11:18
  • 1
    @ChthonicProject I know that OCaml == Objective Caml, and that OOP is available. Still, objects are used far less than functional techniques (OCaml is very much an ML language first and foremost). I have not tried out Java 8 myself, but the support for lambdas looks sweet. However, that alone doesn't even make it remotely similar to OCaml, which relies on idioms and features like structural typing, pattern matching, partial application, type inference, custom operators, recursion, …. Are OCaml and Java similar? They are both imperative OOP languages, soon with higher-order functions. Not quite – amon Dec 06 '13 at 12:00

1 Answers1

10

No, this does not exist. Very few source-to-source compilers exist (I believe some have been tried to port old COBOL codebases to Java). If you want to maintain and modify an OCaml program, your best bet is to learn some OCaml.

gasche
  • 31,259
  • 3
  • 78
  • 100
  • 1
    I don't think I would make the general statement, "Very few source-to-source compilers exist". There are quite a few `languageX-to-JavaScript` compilers nowadays. – Dave L. Sep 05 '13 at 15:17
  • 1
    @david: My statement was to be understood in the context of tools producing source code intended for readability by an human, not a machine. This is not the case of the compilers you mention -- and if you take it that way, any compiler can be described as source-to-source for some notion of "source" that is useless here. – gasche Sep 06 '13 at 13:56
  • 2
    Sorry but that simply isn't true. Take a look at GWT. Why do you think you have to specify the translation to be "pretty", "detailed", "obfuscated", etc? – Dave L. Sep 06 '13 at 17:11
  • 2
    The person asking the question here wants to take an OCaml project, translate it into Java, and then forget about the OCaml source and keep hacking, maintaining and evolving the Java "sources", as if it were a genuine software project (and not unreadable stuff generated by a program). I don't believe GWT can do that in the Java->Javascript direction. Do you have an example of reasonably complex, idiomatic Java source, that turns into a nice-to-read Javascript source? Or am I being trolled about the fact that Javascript is unmaintainable anyway? – gasche Sep 07 '13 at 05:23