Frege is a Haskell for the JVM. Like any Haskell, it is purely functional, enjoys a strong static type system with global type inference and non-strict - also known as lazy - evaluation.
Frege is a Haskell for the JVM.
Like any Haskell, it is purely functional, enjoys a strong static type system with global type inference and non-strict - also known as lazy - evaluation.
Frege compiles to Java, runs on the JVM, and uses any Java library you want. It can be used inside any Java project.
A Taste of Frege
Hello World
This is the classic starter with a slight extension to show the fluent usage from Java and the benefits of having a type system that can recognize purity.
module Hello where
greeting friend = "Hello, " ++ friend ++ "!"
main args = do
println (greeting "World")
This code will compile to Hello.class and Hello.java with a regular Java main method that one can start the usual Java way.
Moreover, the Hello.class will have a method
public static String greeting(String ...) {...}
that one can call from Java or any other JVM language.
The greeting function is pure, meaning it is stateless and free of side effects. Therefore, it is threadsafe and its results may be automatically cached since given the same argument, the result will always be the same.
The main function is impure. It takes a list of Strings and does not return just "void" as in most other JVM languages but the type IO (), telling that it may produce side effects like printing to the console. The Frege type system guarantees that any caller of main must also be of some IO type and is thus also marked as impure. That way, the lack of purity percolates up the whole call chain.
"Hello World" already shows the tenet of "islands of purity" (greeting) in a "sea of imperative code" (main).
Since the purity information is carried through the type system, the compiler can potentially use it for many optimizations such as pre-calculation, deferred execution, parallel execution, caching, and elimination of common subexpressions.
Useful Links
- Getting Started
- Try Frege right from your browser
- Interoperability:
- Differences between Frege and Haskell
- IDE Support
- Build tools