Skip to content

Why Frege compiles to Java

Dierk König edited this page May 15, 2016 · 4 revisions

Frege compiles to Java source code, instead of directly emitting Java byte code. We use the javac Java compiler for that purpose.

We're often asked about the rationale behind this choice and here are some:

  • Frege follows the unix philosophy of composing tools that do their job well. javac compiles Java code well.
  • Calling javac introduces another level of robustness as it ensures the creation of valid byte code.
  • Java code can call other Java code and can be called from Java. Having the Java equivalent of your Frege code makes inter-operation much easier.
  • We follow the very successful approach of GHC that first compiles Haskell down to "core". We first compile to Java as our intermediary language.
  • The Frege compiler becomes conceptually simpler as it is a Haskell-source to Java-source transformation.
  • The 'javac' compiler is highly optimized and continuously improved for various platforms and JVMs. This is all work that we don't have to do.
  • Having the Java source code available opens all kinds of possibilities to use other compilers/transpilers like the ones for Java-to-JavaScript or Java-to-Dalvik (for Android).
  • Generating Java byte code without first going to Java source code would lead to using byte code that has no Java representation. Such code can never be decompiled to Java for inter-operation or debugging purposes.
Clone this wiki locally