-
Notifications
You must be signed in to change notification settings - Fork 145
Calling Frege from Java (from release 3.24 on)
This guide explains how to call code generated by the Frege compiler from Java. It is valid for releases since 3.24.
The Frege Run Time System consists of a handfull of interfaces and abstract classes, which are used to implement laziness, function types and higher kinded types, as explained below. In addition, there are some provisions for IO, parallelism through the Fork-Join framework and concurrency with thread pools. However, none of this requires any initialization, it'll just be there when the Frege code needs it.
Some of the most important runtime types, like functions, lazy values and thunks exist twice in different packages frege.run7
and frege.run8
. The reason is that there is no way to share them between code that uses Java lambdas and code that is compatible with Java7.
This is, for the time being, a dilemma for the author of Java code that calls into Frege. The following solutions are conceivable:
-
Write your Java code inline in Frege. Pro: the Frege compiler will supply the appropriate imports, and the code will run in any Java version. Con: inline code must be written without help from an IDE, and this may become hard. (Workaround: write your code first in a separate module, then copy relevant portions to the frege source)
-
Be future oriented: just forget Java7. Pro: it's the future. Con: javac8 is unable to compile Frege generated code, so this strategy will win only when Java9 becomes the standard.
-
Make a master version for the JVM level you want to support most, but in such a way that you can derive the other version by simply replacing the relevant imports, changing
frege.run7
tofrege.run8
or vice versa. Pro: you can support all Frege users. Con: higher order functions will be difficult, and if you need them, you must use java7 compatible anonymous classes.
Home
News
Community
- Online Communities
- Frege Ecosystem
- Frege Day 2015
- Protocol
- Simon Peyton-Jones Transcript
- Talks
- Articles
- Books
- Courses
Documentation
- Getting Started
- Online REPL
- FAQ
- Language and API Reference
- Libraries
- Language Interoperability
- Calling Frege From Java (old)
- Calling Java From Frege
- Calling Frege From Java (new)
- Compiler Manpage
- Source Code Doc
- Contributing
- System Properties
- License
- IDE Support
- Eclipse
- Intellij
- VS Code and Language Server
- Haskell
- Differences
- GHC Options vs Frege
- Learn You A Haskell Adaptations
- Official Doc
Downloads