SlideShare a Scribd company logo
Frege: Design & Implementation
A short Overview
Ingo Wechsung
IT Consultant, contexo GmbH
Reutlingen, Germany
Topics
• History
• Language Design
• Runtime
• Compiler Architecture
History
• Frege1
• Frege2
• Frege3
see http://www.infoq.com/news/2015/08/frege-haskell-for-jvm
Design Goals
• pure functional, statically typed, non-strict
– essentially Haskell 2010
– plus higher ranked types
– more GHC features to be implemented on top
• easy integration in JVM ecosystem
– a practical JVM language
– a (more funny) way to write (better) Java code
– be as familiar as possible for JVM programmers
Reminder: Haskell means Laziness
… not now,
please! I can do
that later ….
Principles for Design Decisions
• when in doubt, do it like Haskell 2010
– unless it makes no sense in JVM
• module system, FFI, exceptions, C-ish/POSIX-ish APIs
– unless outdated (Functor/Applicative/Monad)
– maybe a bit simpler in certain cases
– subsetting (e.g. standard/prelude libraries)
• add nice JVM stuff
– regexes out of the box
– long, java.lang.String
– types as name spaces (makes records possible)
To err is human …
• class/instance syntax:
class Eq a => Ord a / instance Eq a => Eq (Maybe a)
class Ord Eq a => a / instance Eq Eq a => Maybe a
thought it would be easier to parse, read and
understand, but really is major annoyance.
• Java comment syntax, package/module
• Underestimation of how important source code
compatibility would be.
Unintended Consequences
• for interoperability and speed: support and use
primitive JVM types, hence
data Bool = pure native boolean
• requires literals
– familiarity concerns suggest true, false
• Haskell users [Confused .. Annoyed]
• Yet can‘t fix this easily without „cheating“ in the
compiler.
Too bad your
compiler doesn’t
know what “True”
and “False” is!
Native Interface (aka FFI)
• not only functions, but also data types
• JVM types appear as abstract data types
– need functions (i.e. JVM methods) too
– (watch out: ADT abbreviates abstract as well as
algebraic data types.)
– primitives, interfaces, classes, arrays
– almost no knowledge about „basic types“ hardwired
in the compiler: it‘s all in the Prelude
• Haskell FFI not fit for JVM, replaced with NI
– code that uses C functions is not portable anyway
Runtime
Runtime
• do as much as possible in the NI
• minimalist
• no dependencies
Runtime Concerns
• provide Java methods where
• synchronized { … }
• try { … } catch … finally { … }
would be needed.
• interfaces and classes for representation of
Frege ADT and functions
• thunks & lazy evaluation
Runtime System Overview (to be changed soon)
interface
Applicable
interface
Value
abstract
Algebraic
abstract
Lambda
abstract
Delayed
function
types
algebraic
data types
interface
Lazy
Created by
applied
functions
Current vs. Upcoming Function Handling
● A FunN
, when applied, creates a
FunN-1
, and Fun1
a Delayed.
● designed to minimize class files,
because it covers partial
applications.
● Create FunN
“function pointers”
for functions as needed.
● Re-use function pointers across
modules.
● Higher order functions do not
care about type/arity of passed
functions.
● no partial application
implemented in Java anymore
● thunks/lazy values are
Callable<X>
● higher order functions expect
functional arguments with exact
arity
● should reduce number of
intermediate instances drastically
● will create less class files in Java
8, more in Java 7
● more type safe calling from Java
into Frege
Example
map (1+) list
map ((+) 1) list
List.map(
plus123.apply(1),
list)
…
Fun2 plus123 = new Fun2() {
public Integer eval(Object a1,
Object a2) {
return Delayed.<Integer>forced(a1) +
Delayed.<Integer>forced(a2); }}
map (1+) list
map (x -> 1+x) list
List.map(
(Func1)(x -> 1 +
Thunk.<Integer>forced(x)),
list)
Encoding of Product Types
data P a b = C a b
data R = Pair { !a, !b :: Int }
final class TP {
final Object m1;
final Object m2;
TP(Object a, Object b) {
m1 = a; m2 = b;
}
}
final class TR {
final int mema, memb;
…
}
Encoding of Sum Types
data S a b = S1 a | S2 b interface TS {
static class DS1 implements TS {
DS1 _S1() { return this; }
DS2 _S2() { return null; }
…
}
static class DS2 implements TS
{ … }
public DS1 _S1();
public DS2 _S2();
}
See the REPL!
● There are no secrets in Frege.
● Just type an example in the REPL and use :java
command!
● Caveat: REPL tells you only how things are today.
● JVM evolution may offer opportunities we cannot
refuse.
○ JVM8: lambdas
○ JVM?: value types
Three classes of values
● Immutable
○ All Frege types and pure native types
○ can be used everywhere
● Mutable only
○ JVM types defined mutable native
○ native functions that use them must be IO actions
● Mutable
○ JVM types defined native
○ can appear in ST actions or pure functions
Marshalling in the NI
● no arguments for static method: () -> ST s R
● nullable arguments of type X:
Maybe X or Maybe (Mutable s X)
● void method: ST s () or IO ()
● let return type be X in Frege
○ mutable? Mutable s X
○ nullable? Maybe (...)
○ exceptions? (Ex1 | Ex2 | …)
○ side effects? ST s (...)
Compiler facts
● multi pass
● pass :: StateT Global IO a
● records information about compiled module in the
form of Java annotations
● creates and compiles Java source code
● concurrent -make option
● IDE friendly
Important Compiler Passes
● Lexer :: String -> [Token]
● Parser :: [Token] -> Maybe [Definition]
● Import
● Name resolution
● Type Check
● Transformations & Optimizations
● Strictness
● generate meta data and code
Background Information
Haskell 2010 Report https://www.haskell.
org/definition/haskell2010.pdf
Implementation of FP-Languages http://research.
microsoft.com/en-
us/um/people/simonpj/papers/slpj-book-1987/slpj-
book-1987.pdf
Calling Frege Code from Java https://github.
com/Frege/frege/wiki/Calling-Frege-Code-from-Java

More Related Content

PDF
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
PDF
(3) cpp procedural programming
PPT
C++ to java
PPTX
Why functional programming in C# & F#
PPTX
C++ vs C#
PDF
Java vs. C/C++
PPTX
C++vs java
PDF
Xtext Webinar
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
(3) cpp procedural programming
C++ to java
Why functional programming in C# & F#
C++ vs C#
Java vs. C/C++
C++vs java
Xtext Webinar

What's hot (20)

PPTX
Functional Programming in JavaScript & ESNext
PDF
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
PDF
New c sharp4_features_part_i
KEY
Remix Your Language Tooling (JSConf.eu 2012)
PDF
07 control+structures
KEY
Test-driven language development
ODP
2nd presantation
PPT
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
PPT
Introductory func prog
PPTX
Overview of c language
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
PPTX
Polymorphism 140527082302-phpapp01
PPTX
phases of compiler
PPTX
C# in depth
PPTX
Developer’s viewpoint on swift programming language
PPTX
Functional programming in TypeScript
PPTX
Programming Paradigm & Languages
KEY
Language Engineering in the Cloud
PDF
Functional Groovy - Confess
Functional Programming in JavaScript & ESNext
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
New c sharp4_features_part_i
Remix Your Language Tooling (JSConf.eu 2012)
07 control+structures
Test-driven language development
2nd presantation
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introductory func prog
Overview of c language
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
Polymorphism 140527082302-phpapp01
phases of compiler
C# in depth
Developer’s viewpoint on swift programming language
Functional programming in TypeScript
Programming Paradigm & Languages
Language Engineering in the Cloud
Functional Groovy - Confess
Ad

Viewers also liked (17)

PDF
Frege Tutorial at JavaOne 2015
PDF
FregeFX - JavaFX with Frege, a Haskell for the JVM
PDF
Software Transactional Memory (STM) in Frege
PDF
Frege - consequently functional programming for the JVM
PDF
Quick into to Software Transactional Memory in Frege
PPT
Os Napier
PDF
Os Keysholistic
PDF
Os Ellistutorial
PDF
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
PDF
J Ruby Whirlwind Tour
PDF
Os Keyshacks
PDF
Os Harkins
ODP
Solr Presentation5
PDF
Os Raysmith
PDF
Os Peytonjones
PDF
OCaml Labs introduction at OCaml Consortium 2012
PDF
From object oriented to functional domain modeling
Frege Tutorial at JavaOne 2015
FregeFX - JavaFX with Frege, a Haskell for the JVM
Software Transactional Memory (STM) in Frege
Frege - consequently functional programming for the JVM
Quick into to Software Transactional Memory in Frege
Os Napier
Os Keysholistic
Os Ellistutorial
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
J Ruby Whirlwind Tour
Os Keyshacks
Os Harkins
Solr Presentation5
Os Raysmith
Os Peytonjones
OCaml Labs introduction at OCaml Consortium 2012
From object oriented to functional domain modeling
Ad

Similar to FregeDay: Design and Implementation of the language (Ingo Wechsung) (20)

PDF
Learn You a Frege for Great Good!
PDF
JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...
PDF
JDD2015: Frege - how to program with pure functions - Dierk König
PDF
core java
PDF
What`s new in Java 7
KEY
Polyglot and functional (Devoxx Nov/2011)
PPT
Indic threads pune12-polyglot & functional programming on jvm
PDF
Clojure - An Introduction for Lisp Programmers
PDF
Ola Bini Evolving The Java Platform
PPTX
Proposals for new function in Java SE 9 and beyond
PDF
Clojure - An Introduction for Java Programmers
PDF
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
PPTX
Java se7 features
PDF
Miles Sabin Introduction To Scala For Java Developers
PDF
A Brief Introduction to Scala for Java Developers
PDF
Introduction to clojure
DOCX
Training report anish
KEY
The Joy Of Functional Programming
PPTX
a brief explanation on the topic of Imperative Programming Paradigm.pptx
PDF
SE 20016 - programming languages landscape.
Learn You a Frege for Great Good!
JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...
JDD2015: Frege - how to program with pure functions - Dierk König
core java
What`s new in Java 7
Polyglot and functional (Devoxx Nov/2011)
Indic threads pune12-polyglot & functional programming on jvm
Clojure - An Introduction for Lisp Programmers
Ola Bini Evolving The Java Platform
Proposals for new function in Java SE 9 and beyond
Clojure - An Introduction for Java Programmers
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
Java se7 features
Miles Sabin Introduction To Scala For Java Developers
A Brief Introduction to Scala for Java Developers
Introduction to clojure
Training report anish
The Joy Of Functional Programming
a brief explanation on the topic of Imperative Programming Paradigm.pptx
SE 20016 - programming languages landscape.

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Review of recent advances in non-invasive hemoglobin estimation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Programs and apps: productivity, graphics, security and other tools
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.

FregeDay: Design and Implementation of the language (Ingo Wechsung)

  • 1. Frege: Design & Implementation A short Overview Ingo Wechsung IT Consultant, contexo GmbH Reutlingen, Germany
  • 2. Topics • History • Language Design • Runtime • Compiler Architecture
  • 3. History • Frege1 • Frege2 • Frege3 see http://www.infoq.com/news/2015/08/frege-haskell-for-jvm
  • 4. Design Goals • pure functional, statically typed, non-strict – essentially Haskell 2010 – plus higher ranked types – more GHC features to be implemented on top • easy integration in JVM ecosystem – a practical JVM language – a (more funny) way to write (better) Java code – be as familiar as possible for JVM programmers
  • 5. Reminder: Haskell means Laziness … not now, please! I can do that later ….
  • 6. Principles for Design Decisions • when in doubt, do it like Haskell 2010 – unless it makes no sense in JVM • module system, FFI, exceptions, C-ish/POSIX-ish APIs – unless outdated (Functor/Applicative/Monad) – maybe a bit simpler in certain cases – subsetting (e.g. standard/prelude libraries) • add nice JVM stuff – regexes out of the box – long, java.lang.String – types as name spaces (makes records possible)
  • 7. To err is human … • class/instance syntax: class Eq a => Ord a / instance Eq a => Eq (Maybe a) class Ord Eq a => a / instance Eq Eq a => Maybe a thought it would be easier to parse, read and understand, but really is major annoyance. • Java comment syntax, package/module • Underestimation of how important source code compatibility would be.
  • 8. Unintended Consequences • for interoperability and speed: support and use primitive JVM types, hence data Bool = pure native boolean • requires literals – familiarity concerns suggest true, false • Haskell users [Confused .. Annoyed] • Yet can‘t fix this easily without „cheating“ in the compiler.
  • 9. Too bad your compiler doesn’t know what “True” and “False” is!
  • 10. Native Interface (aka FFI) • not only functions, but also data types • JVM types appear as abstract data types – need functions (i.e. JVM methods) too – (watch out: ADT abbreviates abstract as well as algebraic data types.) – primitives, interfaces, classes, arrays – almost no knowledge about „basic types“ hardwired in the compiler: it‘s all in the Prelude • Haskell FFI not fit for JVM, replaced with NI – code that uses C functions is not portable anyway
  • 12. Runtime • do as much as possible in the NI • minimalist • no dependencies
  • 13. Runtime Concerns • provide Java methods where • synchronized { … } • try { … } catch … finally { … } would be needed. • interfaces and classes for representation of Frege ADT and functions • thunks & lazy evaluation
  • 14. Runtime System Overview (to be changed soon) interface Applicable interface Value abstract Algebraic abstract Lambda abstract Delayed function types algebraic data types interface Lazy Created by applied functions
  • 15. Current vs. Upcoming Function Handling ● A FunN , when applied, creates a FunN-1 , and Fun1 a Delayed. ● designed to minimize class files, because it covers partial applications. ● Create FunN “function pointers” for functions as needed. ● Re-use function pointers across modules. ● Higher order functions do not care about type/arity of passed functions. ● no partial application implemented in Java anymore ● thunks/lazy values are Callable<X> ● higher order functions expect functional arguments with exact arity ● should reduce number of intermediate instances drastically ● will create less class files in Java 8, more in Java 7 ● more type safe calling from Java into Frege
  • 16. Example map (1+) list map ((+) 1) list List.map( plus123.apply(1), list) … Fun2 plus123 = new Fun2() { public Integer eval(Object a1, Object a2) { return Delayed.<Integer>forced(a1) + Delayed.<Integer>forced(a2); }} map (1+) list map (x -> 1+x) list List.map( (Func1)(x -> 1 + Thunk.<Integer>forced(x)), list)
  • 17. Encoding of Product Types data P a b = C a b data R = Pair { !a, !b :: Int } final class TP { final Object m1; final Object m2; TP(Object a, Object b) { m1 = a; m2 = b; } } final class TR { final int mema, memb; … }
  • 18. Encoding of Sum Types data S a b = S1 a | S2 b interface TS { static class DS1 implements TS { DS1 _S1() { return this; } DS2 _S2() { return null; } … } static class DS2 implements TS { … } public DS1 _S1(); public DS2 _S2(); }
  • 19. See the REPL! ● There are no secrets in Frege. ● Just type an example in the REPL and use :java command! ● Caveat: REPL tells you only how things are today. ● JVM evolution may offer opportunities we cannot refuse. ○ JVM8: lambdas ○ JVM?: value types
  • 20. Three classes of values ● Immutable ○ All Frege types and pure native types ○ can be used everywhere ● Mutable only ○ JVM types defined mutable native ○ native functions that use them must be IO actions ● Mutable ○ JVM types defined native ○ can appear in ST actions or pure functions
  • 21. Marshalling in the NI ● no arguments for static method: () -> ST s R ● nullable arguments of type X: Maybe X or Maybe (Mutable s X) ● void method: ST s () or IO () ● let return type be X in Frege ○ mutable? Mutable s X ○ nullable? Maybe (...) ○ exceptions? (Ex1 | Ex2 | …) ○ side effects? ST s (...)
  • 22. Compiler facts ● multi pass ● pass :: StateT Global IO a ● records information about compiled module in the form of Java annotations ● creates and compiles Java source code ● concurrent -make option ● IDE friendly
  • 23. Important Compiler Passes ● Lexer :: String -> [Token] ● Parser :: [Token] -> Maybe [Definition] ● Import ● Name resolution ● Type Check ● Transformations & Optimizations ● Strictness ● generate meta data and code
  • 24. Background Information Haskell 2010 Report https://www.haskell. org/definition/haskell2010.pdf Implementation of FP-Languages http://research. microsoft.com/en- us/um/people/simonpj/papers/slpj-book-1987/slpj- book-1987.pdf Calling Frege Code from Java https://github. com/Frege/frege/wiki/Calling-Frege-Code-from-Java