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
85
votes
4 answers

Haskell on JVM?

I'm wondering if there is some way to make Haskell run on the JVM (compiled or interpreted)? There exists JHaskell on Sourceforge but this one seems to be empty and dead. GHC uses LLVM as compiler backend. Would it be a good idea or possible to…
jeha
  • 10,562
  • 5
  • 50
  • 69
33
votes
3 answers

What are the main differences between Scala and Frege (in programming paradigms)?

Scala and Frege are both typed functional languages that target JVM. Frege is closer to Haskell, Scala has a more independent history. But if we don't look at syntactic differences, what are the differences in the allowed programming techniques,…
27
votes
5 answers

How to run Frege programs on Android?

I'm interested in programming for Android in functional languages, preferably close to Haskell. Frege seems to be a good choice. I found that somebody has already done such a proof-of-concept application, but I couldn't find its sources or anything…
Petr
  • 62,528
  • 13
  • 153
  • 317
18
votes
3 answers

Is there a good reason why `deleteBy` does not have its most general type?

The Haskell 2010 Language Report states in section 20.10.1.1 that: deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] In fact, the implementation in the GHC library would allow deleteBy :: (b -> a -> Bool) -> b -> [a] -> [a] but actually restricts…
Ingo
  • 36,037
  • 5
  • 53
  • 100
15
votes
1 answer

Frege's equivalent of Haskell's getLine and read

Is there any Frege's equivalent of Haskell's getLine and read to parse input from the console in the standard library? Currently I am doing it like this: import frege.IO getLine :: IO String getLine = do isin <- stdin isrin <-…
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
14
votes
1 answer

Does Frege perform tail call optimization?

Are tail calls optimised in Frege. I know that there is TCO neither in Java nor in languages which compile to JVM bytecode like Clojure and Scala. What about Frege?
haskelline
  • 1,116
  • 7
  • 15
9
votes
1 answer

Akka with Frege running slower than Scala counterpart

As an exercise, I took these Scala and Java examples of Akka to port to Frege. While it works fine, it runs slower(11s) than Scala(540ms) counterpart. module mmhelloworld.akkatutorialfregecore.Pi where import…
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
7
votes
1 answer

How do Frege classes work?

It seems that Frege's ideas about type-classes differ significantly from Haskell. In particular: The syntax appears to be different, for no obvious reason. Function types cannot have class instances. (Seems a rather odd rule...) The language spec…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
6
votes
1 answer

What is the difference between "package" and "module" in Frege?

Hi I've been playing a little bit with Frege and I just noticed in some examples that package and module are used interchangeably: package MyModuleOne where and sometimes: module MyModuleTwo where When importing from one or the other I don't see…
Janus Lynd
  • 209
  • 1
  • 8
6
votes
1 answer

QuickCheck: How to combine two generators?

I have two generators, gen_n & gen_arr: gen_n :: Gen Int gen_n = suchThat arbitrary (\i -> i >= 0 && i <= 10) gen_elem :: Gen Int gen_elem = suchThat arbitrary (\i -> i >= 0 && i <= 100) gen_arr :: Gen [Int] gen_arr = listOf gen_elem How can I…
muhuk
  • 15,777
  • 9
  • 59
  • 98
6
votes
1 answer

How does Frege generalize number literals?

It appears that Frege can evaluate 1/2 to return the Double value 0.5. The literal 1 is of type Int. It seems to be promoted to Double, which is a type in the Real class and thus knows the / operator. How does this happen? Is it using the Haskell…
Dierk
  • 1,308
  • 7
  • 13
6
votes
5 answers

Expression eager in Frege but lazy in Haskell?

In Haskell, the following code prints "[1,2,3,4,5": foo = take 10 $ show $ numbersFrom 1 where numbersFrom start = start : numbersFrom (start + 1) -- could use [1..] But in Frege, It throws OutOfMemoryError with the following code: foo = take 10…
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
5
votes
1 answer

Haskell/Frege <=< and =<< associativity

According to Hoogle, the fixity of <=< (Kleisli monad composition, or "left fish") and =<< (reverse monad bind) is infixr 1. If I'm looking at them correctly, an expression like, say print <=< return =<< return "foo" should be invalid, since it…
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
5
votes
1 answer

Recursion and StackOverflowError

How would you adjust this simple recursion example so that tail call optimization occurs (and not a StackOverflowError)? count 0 = 0 count n = succ (count (pred n)) count 100000
Dave Moten
  • 11,957
  • 2
  • 40
  • 47
5
votes
1 answer

Use Frege List from Java code

I would like to understand how Frege List works and how is it possible to use it from Java. While I downloaded the Frege compiler code, I found difficult to understand what a Frege List is from the Frege code. Doing some tests I saw that a Frege…
mariop
  • 3,195
  • 1
  • 19
  • 29
1
2 3 4 5 6 7 8