Questions tagged [frege]

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

  1. Getting Started
  2. Try Frege right from your browser
  3. Interoperability:
  4. Differences between Frege and Haskell
  5. IDE Support
  6. Build tools
107 questions
1
vote
2 answers

Import Java library in Frege

I'm trying out frege, and I'm struggling to try to use some native Java libraries. I'm trying it out with the leiningen plugin, and Joda time. Apparently the lein plugin doesn't take care of correctly seeting the classpath for fregec, or maybe it's…
berdario
  • 1,851
  • 18
  • 29
1
vote
2 answers

Mutable references to immutable data in Haskell

I'd like to keep track of a "current" value in a succession of immutable values. What is the best way to do that in Haskell without introducing a new reference for every new value? Here is an example: data Person = Person {name, level, topic ::…
Dierk
  • 1,308
  • 7
  • 13
1
vote
1 answer

Use java.util.Properties in Frege

I'm trying to use frege.java.Util module to construct a Properties instance. Here's the code: module frege_test.Application where import frege.java.Util (Properties) main :: [String] -> IO Int main _ = do properties <- Properties.new () return…
ForNeVeR
  • 6,726
  • 5
  • 24
  • 43
1
vote
1 answer

what is the easiest way to pass a list of integers from java to a frege function?

Assume I have a Frege module module Util where total :: [Int] -> Int total xs = fold (+) 0 xs If "total" was written in Java, I could call it via Util.total(Arrays.asList(1,2,3)); What is the best way to call the Frege implementation from Java?
Dierk
  • 1,308
  • 7
  • 13
1
vote
1 answer

How can I specialize a type in a Frege QuickCheck?

I'd like to run the classical test for reversing a list. To this end, I have to specialize the list to a list of "Arbitrary" (sic!) types, e.g. [Int]. What works is module ListCheck where import Test.QuickCheck myReverse :: [Int] ->…
Dierk
  • 1,308
  • 7
  • 13
1
vote
3 answers

Building a Jar of a Frege project using Gradle

I would like to: use the Frege programming language to write a simple "Hello World" piece of code, then using the Frege compiler generating the equivalent Java source code, then building an executable Jar file to run from the command line, all the…
TPPZ
  • 4,447
  • 10
  • 61
  • 106
1
vote
1 answer

How to enable hints and warnings in the online REPL

I figured that I can do it on the command line REPL like so: java -jar frege-repl-1.0.3-SNAPSHOT.jar -hints -warnings But how can I do the same in http://try.frege-lang.org
Ingo
  • 36,037
  • 5
  • 53
  • 100
1
vote
1 answer

are binary operations in Frege different from Haskell?

I tried to convert Haskell code that calculates the Adler-32 hash of 'a' into Frege but got 6422626 instead of 300286872 Excerpt from the Haskell code at http://book.realworldhaskell.org/read/functional-programming.html adler32_try2 xs = helper…
Dierk
  • 1,308
  • 7
  • 13
1
vote
1 answer

How can I "set" a field in a record in Frege?

suppose I have these records: data Group = Group { id :: Id, name :: Name } derive Show Group data Game = Game { world :: World, groups :: [Group], random :: FRandom } derive Show Game I would like to add a new group to game, but I would like to…
Federico Tomassetti
  • 2,100
  • 1
  • 19
  • 26
1
vote
1 answer

is there an upper limit for the length function on lists in Frege?

For the real-world-frege project I did the exercise from real-world-haskell where the assignment is to create a length function for lists and to compare it against the internal length function. My proposed solution is under…
Dierk
  • 1,308
  • 7
  • 13
1
vote
1 answer

Is there a downloadable jar for the Frege JSR223 integration?

The frege-scripting project on github contains the ScriptEngineFactory as required for JSR223 but it appears that is neither packaged in the Frege language jar itself nor in the REPL or any of its dependencies. Is there such a jar somewhere or does…
Dierk
  • 1,308
  • 7
  • 13
1
vote
1 answer

How to print an empty literal list in Frege

I tried println [ ] but got unknown context: Show <3298 a> Is that not supported by design or is my code wrong?
Dierk
  • 1,308
  • 7
  • 13
0
votes
0 answers

Does Frege transpiles directly to Java source code?

I am thinking of using Frege in a Java project. I need that the compiler generates plain Java source files, not class files. -- I looked at the Frege wiki, but could not determine whether this is the case.
halloleo
  • 9,216
  • 13
  • 64
  • 122
0
votes
1 answer

Incomplete Frege Documentation

The javadocs at http://www.frege-lang.org/doc/index.html seem to be missing quite a bit (namely, no frege.prelude package), and does not seem very up to date. Might there be a good documentation for Frege hidden in plain sight somewhere?
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
0
votes
1 answer

Does Frege solve the issue of "re-export qualified" of Haskell?

The issue in Haskell: module Foo.A where foo = 42 and module Foo.B where foo = 12 and you want to write a super module module Foo ( module Foo.A , module Foo.B ) where import Foo.A import Foo.B which re-exports those modules,…
Incerteza
  • 32,326
  • 47
  • 154
  • 261