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
3
votes
3 answers

What is the difference between <- and "let" inside do blocks?

I don't understand when do I have to use let and when do I have to use the <- binding.
E.F
  • 199
  • 1
  • 1
  • 10
3
votes
2 answers

What is type of native constructor which throws exception in Frege?

I'm trying to figure out native interface. I'm trying to send some message using UDP. Here what I have: module UDPTest where data StringAsBytes = native java.lang.String where native getBytes :: String -> ST s (Mutable s (JArray Byte)) …
libnull-dev
  • 881
  • 1
  • 7
  • 19
3
votes
2 answers

Creating instance of State in Frege

In y-taka-23 adaptation of LYAH I found that most of snippets for Chapter 13 must deal with lack of State constructor, for example original Haskell code: randomSt = State random is rewritten as: randomSt = do gen <- State.get let (x,…
libnull-dev
  • 881
  • 1
  • 7
  • 19
3
votes
1 answer

Use parentheses to disambiguate an expression like `liftM b ap c`

While in Haskell, the following works: > (+) `liftM` (Just 3) `ap` (Just 5) Just 8 Frege hints to use parantheses: frege> (+) `liftM` (Just 3) `ap` (Just 5) E .fr:12: invalid expression, none-associative operator liftM found on same…
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
3
votes
1 answer

What would change if a JVM Language Compilation process had an STG phase like Haskell?

I had a friend say: For me the most interesting thing about Haskell is not the language and the types. It is the Spineless Tagless Graph Machine behind it. Because Haskell people talk about types all the time, this quote really caught my…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
3
votes
1 answer

Explicit module exports in Frege

I am posting this after reading the Frege language specification and looking for examples using search engines. I hope I have not overlooked an obvious answer. I am trying to port some Haskell code to Frege and I cannot find any documentation…
Giorgio
  • 5,023
  • 6
  • 41
  • 71
3
votes
2 answers

Problems with Code in the Frege REPL

While trying to learn Frege I copied some code from Dierk's Real World Frege to the online REPL an tried to execute it (see also How to execute a compiled code snipped in Frege online repl). The scripts I've tried don't compile :-( What am I doing…
rdmueller
  • 10,742
  • 10
  • 69
  • 126
3
votes
1 answer

Can Functor instance be declared with additional type restriction for function

I'm working on porting GHC/Arr.hs into Frege. Array is defined: data Array i e = Array{u,l::i,n::Int,elems::(JArray e)} There is function: amap :: (Ix i, ArrayElem e) => (a -> b) -> Array i a -> Array i b Now, I don't know how to define Functor…
Lech Głowiak
  • 366
  • 4
  • 8
3
votes
1 answer

How to handle exceptions in Frege?

Trying to handle a exception I found a related question talking about this: what is the Frege equivalent to Haskell's "interact" function? But it wasn't clear to me how to use the try/catch/finally expressions. The problem: I wanted to read a file…
Janus Lynd
  • 209
  • 1
  • 8
3
votes
1 answer

How do I declare Java enums in Frege native declarations?

When using the Frege native-gen tool on the JavaFX Animation class it generates Frege code that includes the following: data Animation = mutable native javafx.animation.Animation where native getRate :: Animation -> IO Double native getStatus…
Dierk
  • 1,308
  • 7
  • 13
3
votes
1 answer

How to call Frege from Java in Eclipse?

I couldn't find a single out-of-the-box example on this topic. I succeeded in calling from Frege to Frege, as well as from Java to Java in the same project, but I couldn't get the .java-files to recognize the .fr-files What steps should I follow to…
Cirquit
  • 464
  • 2
  • 9
3
votes
2 answers

What is the Frege equivalent to Haskell "readFile"?

While preparing the Frege equivalents for the Real-world Haskell code examples (chapter 2), I could not find the equivalent for :type readFile What would be the closest match?
Dierk
  • 1,308
  • 7
  • 13
3
votes
1 answer

Can I use Frege in my project via a maven dependency?

If Frege had a POM and was uploaded to maven central or bintray, I could easily use it as a maven dependency in maven, gradle, buildr, and via grapes. I couldn't find it, though. Is there any such thing? I would not require a full maven plugin.
Dierk
  • 1,308
  • 7
  • 13
2
votes
1 answer

How to evaluate/run frege IO () monad from java?

First of all sorry for my English, and for the fact that I'm trying to learn Haskell I would run Frege code (Haskell) calling from java, for almost all aspects I managed to make it all work as per instructions found on various sites ... but I still…
2
votes
1 answer

How can I create a new ViewPager in froid

I'm using froid to write Android applications and I can't seem to find documentation on how to make a ViewPager. How do I go about making a custom one?
user3574294
  • 199
  • 1
  • 7