Neha Patil (Editor)

Frege (programming language)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Designed by
  
Ingo Wechsung

OS
  
Cross-platform

Frege (programming language)

Paradigm
  
functional, lazy/non-strict

First appeared
  
2011; 6 years ago (2011)

Stable release
  
3.24 / 12 March 2016; 11 months ago (2016-03-12)

Typing discipline
  
static, strong, inferred

Frege is a non-strict, purely functional programming language for the Java virtual machine in the spirit of Haskell.

Contents

It is considered a Haskell dialect or simply "a" Haskell for the Java virtual machine.

Frege has a strong static type system with type inference. Higher rank types are supported, though type annotations are required for that. Frege programs are compiled to Java bytecode and run in a Java virtual machine. Existing Java classes and methods can be used seamlessly from Frege after their types have been properly declared.

The language was designed by Ingo Wechsung, who named it after the German mathematician, logician and philosopher Gottlob Frege.

(Unrelated to the Frege Program Prover).

Comparison with Haskell

A summary of differences between Frege and Haskell is listed at the Differences between Frege and Haskell.

The type String is custom defined as an interface with Java strings. String (++) is bound to Java's String (+). Conversion functions to Haskell correspondent:

Literals:

Frege's Monad class does not include the method fail, included in a separate class MonadFail.

Numeric classes for floating point types are also different. Haskell's classes Fractional, RealFrac, RealFloat and Floating are not defined. Haskell's class Real defines toRational while Frege's defines (/):

Compiling Frege programs

Frege requires Java-7 JDK or higher to compile and run.

At the console

As the "Getting started" page states, to compile it:

This assumes the downloaded frege3.xx.vvv.jar has been renamed to fregec.jar for ease of use.

To run the compiled program specify the package name as start class. On Linux and other Unix systems:

On Microsoft Windows the classpath separator has to be changed to ';'

At the Eclipse devel. environment

There is a plug-in for Eclipse with instructions given at How-to EclipseFregIDE.

Records

Unlike in Haskell, the record fields do not appear in the global namespace. Thus it is possible to reuse the same field name in different types. The accessor functions in the example are known as Person.name and Person.birthyear

The record syntax is really syntactic sugar, and the associated data constructor can be used with traditional or record syntax. The same holds for patterns.

Record pattern syntax allows to check for a given constructor and check specific fields or bind them to local variables. This makes patterns independent from the number and order of fields in a constructor.

References

Frege (programming language) Wikipedia