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
1 answer

Searching for existing Frege java native bindings such as java.nio.file.Path

I am trying to port a simple java project over to Frege for practice. I spent a bit of time looking for bindings for java.nio.file.Path, among other things. I found https://github.com/Frege/frege/blob/master/frege/java/IO.fr, which is close, but…
Justin Thomas
  • 283
  • 1
  • 6
1
vote
1 answer

How can I get the Frege compiler to see Android API classes when using Gradle?

I am attempting to write an Android app using the Frege language. Unfortunately, I'm not aware of any examples of how to do this. So, I'm using Gradle as my build system, with the Android Gradle plugin. Then to get the Frege code to be compiled,…
user31708
  • 630
  • 5
  • 11
1
vote
2 answers

Frege trace not printing

As the title says, for some reason, messages passed to the trace (well, a variant of which) function don't show up properly when debugging functions. Simply flushing stdout/stderr doesn't seem to do anything, either. -- Makes it more like Haskell's…
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
1
vote
1 answer

Regex literal in Frege

What is an unicode code for grave accent mark used to specify regex literal in Frege?
libnull-dev
  • 881
  • 1
  • 7
  • 19
1
vote
1 answer

What does "build:" mean in the java -cp option?

I was learning about Frege and saw this command line: $ java -Xss1m -cp build:fregec.jar examples.SimpleIO I've never seen that build: before. What does that mean and what does it do? More context: https://github.com/Frege/frege/issues/289 I…
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
1
vote
1 answer

How to implement Java interfaces in Frege?

I have been trying out Frege and one of the first things I would like to do is implement a Java interface. How is that done? Here's my example in Java: package mypkg; import frege.repl.FregeRepl; import frege.runtime.Concurrent; import…
Renato
  • 12,940
  • 3
  • 54
  • 85
1
vote
1 answer

Passing Values From Frege to Java and Back

Suppose I have a dumb Frege function that constructs a pair of Nums. newPair :: (Num α, Num β) => α -> β -> (α, β) newPair = (,) -- alternatively -- newPair x y = (x, y) Attempting to call this function from Java, however, a PreludeBase.CNum<α> and…
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
1
vote
1 answer

Frege can't find classes in referenced project or external jar

I think I'm making a simple mistake here, but I can't get Frege to find any classes outside of the local Eclipse project. I have a working non-trivial Java project (that's not mine), that I do not want to modify. I want to have a new clean Frege…
parker.sikand
  • 1,371
  • 2
  • 15
  • 32
1
vote
2 answers

Sequencing basic parsers in Haskell and Frege using do notation

I try to run snippets from chapter 8 about functional parsers in Graham Hutton's 'Programming in Haskell' both in ghci and frege-repl. I'm not able to sequence parsers using do syntax. I have following definitions in Frege (Haskell version differs…
libnull-dev
  • 881
  • 1
  • 7
  • 19
1
vote
1 answer

Is there any way to enable n+k patterns in Frege?

In Haskell I have to start ghci with -XNPlusKPatterns or add {-# LANGUAGE NPlusKPatterns #-} in source file to make this work: pred :: Int -> Int pred 0 = 0 pred (n + 1) = n Is n+k pattern deliberately passed over in Frege or there exists a way to…
libnull-dev
  • 881
  • 1
  • 7
  • 19
1
vote
1 answer

Could not import module frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)

I tried to import System.Directory in my Frege program (In Eclipse) in order to use functions as getDirectoryContent, etc., and it writes me this error : Could not import module frege.system.Directory (java.lang.ClassNotFoundException:…
E.F
  • 199
  • 1
  • 1
  • 10
1
vote
0 answers

Installing ghc-mod on Windows 7 freezes forever

I want to enable Frege, basically Haskell on JVM (https://github.com/Frege) in IntelliJ IDEA. It requires path to ghc-mod and ghc-modi. Therefore, I installed Haskell Platform for Windows 64 bit. Since Cabal is already part of the Platform, I…
user2039784
  • 199
  • 9
1
vote
1 answer

frege pure functions and performance optimizations

My understanding of haskell's pure functions is that they enable performance optimizations like caching (because a pure function returns the same result for the same input every time). What performance optimizations occur for frege's pure functions?
Dave Moten
  • 11,957
  • 2
  • 40
  • 47
1
vote
2 answers

Creating frege.jar and including intermediate .java files (for use with J2ObjC)

Is there a way to compile the Frege runtime and libraries to just their .java intermediates? I'm trying to use Frege as part of an iOS app via J2ObjC, which can't parse .class files.
Charles Maria
  • 2,165
  • 15
  • 15
1
vote
1 answer

Mapping Java Array to Frege

Lets say I'd like to map the Java code: package mypackage; class A { public String[] values() { return new String[]{"one", "two"}; } } To its Frege counterpart: data AA = pure native mypackage.A where native values :: AA ->…
Janus Lynd
  • 209
  • 1
  • 8