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

Writing an Android app purely in Frege

I've been looking into this for a while now but there seems to be old solutions that focus on mainly calling frege from Java. Is there a way to write an complete app/Activity purely in Frege? If not, why?
user3574294
  • 199
  • 1
  • 7
2
votes
1 answer

Type not as polymorphic as suggested

I'm trying to make a Functor instance for the following data type: data Event t a = Event { runEvent :: t -> ([a], Event t a) } instance Functor (Event t) where fmap :: (a -> b) -> Event t a -> Event t b fmap f e = Event go where …
Michael Chav
  • 441
  • 5
  • 15
2
votes
2 answers

How to run generated frege java code on jvm?

hello world in haskell frege : hello.fr : module Hello where main args = do putStrLn "Hello, World!" This code generates hello.java : /* Source code is in UTF-8 encoding. The following symbols may appear, among others: α β γ δ ε ζ η θ ι…
blue-sky
  • 51,962
  • 152
  • 427
  • 752
2
votes
1 answer

Which projects have been ported successfully from Haskell to Frege?

I'd like to learn how to port Haskell code to Frege. Are there any projects that have already been ported and serve as good examples?
Stefanus
  • 1,619
  • 3
  • 12
  • 23
2
votes
2 answers

Frege Double to Integer

I would like to be able to convert a large Double to an Integer, but it seems that the Frege Haskell implementation of floor does not yield an Integral type. Instead, it seems to be implemented to interface with way Java does it, and takes a…
Mona the Monad
  • 2,265
  • 3
  • 19
  • 30
2
votes
1 answer

What is Frege equivalent to Haskell's Fractional?

This definition is valid in ghci: recip :: Fractional a ⇒ a → a recip n = 1 / n Trying it in frege-repl I got: E .fr:6: can't resolve `Fractional`, did you mean `Exceptional` perhaps? "Hoogling" Fractional gives me nothing.
libnull-dev
  • 881
  • 1
  • 7
  • 19
2
votes
2 answers

Why do I get these type errors?

I have a data type: data Tree = Empty | Node Int Tree Tree and I want function nodeDepth :: Tree -> [(Int, Int)] one pair for each node. The first element is label (value )and the second one is its depth. My intention (raw code) is like…
tikael
  • 439
  • 4
  • 15
2
votes
1 answer

takeWhile for an infinite IO list

I'm trying to consume an infinite list which may contain elements of type: IO (Either Throwable a) I'm only interested in consuming elements of type Right. List is sorted. Right elements are always first and then Left elements The problem is…
Janus Lynd
  • 209
  • 1
  • 8
2
votes
1 answer

How to execute a compiled code snipped in Frege online repl

OK, I guess this is a stupid beginners question: I try to learn Frege through the online repl. For doing so, I though it would be a good idea to paste code examples from Dierk's Real World Frege to the upper right window of the repl, press compile…
rdmueller
  • 10,742
  • 10
  • 69
  • 126
2
votes
1 answer

Is it possible to use frege with Play framework

I'm searching a language for a new project. It's web based project and I want to adopt a REST architecture. I also want a function programming language. I have the choice between Haskell (because it's cool) and Scala (because of the Play Framework).…
Emrys Myrooin
  • 2,179
  • 14
  • 39
2
votes
2 answers

Parsing JSON values

Lets say I have the following structure: import Data.JSON import Data.List data Lang = Lang { name :: String, desc :: String } derive Show Lang instance ToJSON Lang where toJSON Lang{name, desc} = Struct [ …
Janus Lynd
  • 209
  • 1
  • 8
2
votes
2 answers

Calling Frege From Java Doesn't Match Number of Parameters

I have Frege code as follows (mostly, just pay attention to the type signature for getDatabase) module fregeHelper.FregeCode where --Java's String.split method pure native split :: String -> String -> JArray String --Java's ArrayList data…
Crazycolorz5
  • 747
  • 6
  • 12
2
votes
1 answer

How do I declare Maybe of a mutable type in an non-pure native function in Frege?

The native-gen tool generates the native declaration for the showOpenDialog method in javafx.stage.FileChooser like so data FileChooser = mutable native javafx.stage.FileChooser where native showOpenDialog :: FileChooser -> Window -> IO…
Dierk
  • 1,308
  • 7
  • 13
2
votes
1 answer

How can I handle binary data in Frege?

I'm new to Frege, although I know both Java and Haskell. I'm porting some Haskell code that uses ByteString, and I'm trying to figure out what to use in Frege. I assume I would want to use something whose underlying Java representation is byte[],…
user31708
  • 630
  • 5
  • 11
2
votes
1 answer

How do I declare a native interface with type variables in Frege?

I'd like to natively declare a java interface in Frege that has a generic type. For example let's take an ObservableList from JavaFX. Leaving out the generic type E, it works to define data ObservableList = mutable native…
Dierk
  • 1,308
  • 7
  • 13