SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
Frege 
Purely Functional Programming 
on the JVM
Dierk König 
Canoo 
mittie
Frege - purely functional programming on the JVM
Frege is different
Frege is very different
You would not believe 
just how different it is!
Online REPL 
http://try.frege-lang.org
Define a Function 
frege> 
times 
a 
b 
= 
a 
* 
b 
frege> 
times 
3 
4 
12 
frege> 
:type 
times 
Num 
α 
=> 
α 
-­‐> 
α 
-­‐> 
α
Define a Function 
frege> 
times 
a 
b 
= 
a 
* 
b 
frege> 
(times 
3) 
4 
12 
frege> 
:type 
times 
Num 
α 
=> 
α 
-­‐>(α 
-­‐> 
α) 
no types declared 
function appl. 
left associative 
tell the inferred 
type 
typeclass 
only 1 
parameter! 
return type is 
a function! 
thumb: „two params 
of same numeric type 
returning that type“ 
no comma
Reference a Function 
frege> 
twotimes 
= 
times 
2 
frege> 
twotimes 
3 
6 
frege> 
:t 
twotimes 
Int 
-­‐> 
Int
Reference a Function 
frege> 
twotimes 
= 
times 
2 
frege> 
twotimes 
3 
6 
frege> 
:t 
twotimes 
Int 
-­‐> 
Int 
No second 
argument! 
„Currying“, „schönfinkeling“, 
or „partial function 
application“. 
Concept invented by 
Gottlob Frege. 
inferred types 
are more specific
Function Composition 
frege> 
twotimes 
(threetimes 
2) 
12 
frege> 
sixtimes 
= 
twotimes 
. 
threetimes 
frege> 
sixtimes 
2 
frege> 
:t 
sixtimes 
Int 
-­‐> 
Int
Function Composition 
frege> 
twotimes 
(threetimes 
2) 
f(g(x)) 
12 
more about this later 
frege> 
sixtimes 
= 
twotimes 
. 
threetimes 
frege> 
sixtimes 
2 
(f ° g) (x) 
frege> 
:t 
sixtimes 
Int 
-­‐> 
Int
Pattern Matching 
frege> 
times 
0 
(threetimes 
2) 
0 
frege> 
times 
0 
b 
= 
0
Pattern Matching 
frege> 
times 
0 
(threetimes 
2) 
0 
unnecessarily evaluated 
frege> 
times 
0 
b 
= 
0 
pattern matching shortcutting
Lazy Evaluation 
frege> 
times 
0 
(length 
[1..]) 
0 endless sequence 
evaluation would never stop 
Pattern matching and 
non-strict evaluation 
to the rescue!
Pure Functions 
Java 
T 
foo(Pair<T,U> 
p) 
{…} 
Frege 
foo 
:: 
(α,β) 
-­‐> 
α 
What could 
possibly happen? 
What could 
possibly happen?
Pure Functions 
Java 
T 
foo(Pair<T,U> 
p) 
{…} 
Frege 
foo 
:: 
(α,β) 
-­‐> 
α 
Everything! 
NPEs, state 
changes, endless 
loops, missile 
launch,… 
a is returned 
or 
system error
Java Interoperability
Java -> Frege 
Scripting: 
JSR 
223 
Service: 
compile 
*.fr 
file 
put 
on 
javac 
classpath 
call 
static 
method 
simple
Frege -> Java 
! 
! 
data Date = native java.util.Date where 
Declaring the messiness. 
native new :: () -> IO (MutableIO Date) -- new Date() 
native toString :: Mutable s Date -> ST s String -- d.toString() 
This is a key distinction between Frege and 
previous efforts to port Haskell to the JVM.
Some Cool Stuff
Zipping 
addzip 
[] 
_ 
= 
[] 
addzip 
_ 
[] 
= 
[] 
addzip 
(x:xs) 
(y:ys) 
= 
(x 
+ 
y 
: 
addzip 
xs 
ys 
)
Zipping 
addzip 
[] 
_ 
= 
[] 
addzip 
_ 
[] 
= 
[] 
addzip 
(x:xs) 
(y:ys) 
= 
(x 
+ 
y 
: 
addzip 
xs 
ys 
) 
! 
use as 
addzip 
[1,2,3] 
[1,2,3] 
== 
[2,4,6] 
Pattern matching 
feels like Prolog 
Why only for the (+) function? 
We could be more general…
High Order Functions 
zipWith 
f 
[] 
_ 
= 
[] 
zipWith 
f 
_ 
[] 
= 
[] 
zipWith 
f 
(x:xs) 
(y:ys) 
= 
(f 
x 
y 
: 
zipWith 
xs 
ys 
) 
! 
!
invented by Gottlob Frege 
High Order Functions 
zipWith 
f 
[] 
_ 
= 
[] 
zipWith 
f 
_ 
[] 
= 
[] 
zipWith 
f 
(x:xs) 
(y:ys) 
= 
(f 
x 
y 
: 
zipWith 
xs 
ys 
) 
use as 
zipWith 
(+) 
[1,2,3] 
[1,2,3] 
== 
[2,4,6] 
and, yes we can now define 
addzip 
= 
zipWith 
(+)
Fibonacci 
! 
fib 
= 
0: 
1: 
addzip 
fib 
(tail 
fib) 
! use as 
take 
60 
fib 
a new solution approach 
fib 
0:1 
… 
tail 
1 
… 
zip 
1 
…
Fibonacci 
! 
fib 
= 
0: 
1: 
addzip 
fib 
(tail 
fib) 
! use as 
take 
60 
fib 
a new solution approach 
fib 
0 
1:1 
… 
tail 
1 
… 
zip 
2 
…
Fibonacci 
! 
fib 
= 
0: 
1: 
addzip 
fib 
(tail 
fib) 
! use as 
take 
60 
fib 
a new solution approach 
fib 
0 
1 
1:2 
… 
tail 
2 
… 
zip 
3 
…
Fibonacci 
! 
fib 
= 
0: 
1: 
addzip 
fib 
(tail 
fib) 
! use as 
take 
60 
fib 
a new solution approach 
fib 
0 
1 
1 
2:3 
… 
tail 
3 
… 
zip 
5 
…
List Comprehension 
Pythagorean triples: a2 + b2 = c2! 
[ 
(m*m-­‐n*n, 
2*m*n, 
m*m+n*n) 
| 
m 
<-­‐ 
[2..], 
n 
<-­‐ 
[1..m-­‐1] 
] 
!
List Comprehension 
Pythagorean triples: a2 + b2 = c2! 
[ 
(m*m-­‐n*n, 
2*m*n, 
m*m+n*n) 
| 
m 
<-­‐ 
[2..], 
n 
<-­‐ 
[1..m-­‐1] 
] 
! 
endless production 
triples 
think „nested loop“
QuickCheck 
-­‐-­‐ 
An 
AVL 
tree 
is 
balanced 
so 
that 
the 
height 
of 
the 
left 
and 
right 
subtree 
differ 
by 
at 
most 
1 
p_balance 
= 
forAll 
aTree 
(tree 
-­‐> 
abs 
tree.balance 
< 
2) 
! QuickCheck will create 500 different trees 
covering all corner cases in creation and 
validate the invariant. (from Frege source code)
Type System 
Hindley-Milner 
more info for the programmer 
less work for the programmer 
more useful programs compile 
less bad programs compile 
http://perl.plover.com/yak/typing/ 
Endless recursion in merge sort detected by the type system.
Keep the mess out! 
Mutable 
I/O 
Mutable 
Clean Computation 
Clean Computation 
Mutable 
Clean Computation
Keep the mess out! 
Mutable 
I/O 
Mutable 
Clean Computation 
Clean Computation 
Mutable 
Clean Computation 
Ok, these are Monads. Be brave. Think of them as contexts 
that the type system propagates and makes un-escapable.
History 
Java promise: „No more pointers!“! 
But NullPointerExceptions (?)
Frege is different 
No More But 
state no state (unless declared) 
statements expressions (+ „do“ notation) 
interfaces type classes 
classes & objects algebraic data types 
inheritance polymorphism 
null references Maybe 
and the list goes on…
Frege in comparison 
useful 
safe 
Groovy 
Java 
Frege 
Haskell
Frege in comparison 
useful 
safe 
Groovy 
Java 
Frege 
Haskell 
concept by 
Simon Peyton-Jones 
Frege makes the Haskell spirit 
accessible to the Java programmer 
and provides a new level of safety. 
apply logic 
run computers
Why FP matters 
The intellectual challenge 
The aesthetical enjoyment 
Type system and modularity benefits! 
It may even be useful! 
„An investment in knowledge 
always pays the best interest.“ 
—Benjamin Franklin
How? 
http://www.frege-­‐lang.org 
stackoverflow 
„frege“ 
tag 
https://github.com/Dierk/Real_World_Frege 
Join the effort!
Gottlob 
Frege 
"As I think about acts of integrity and grace, 
I realise that there is nothing in my knowledge 
that compares with Frege’s dedication to truth… ! 
It was almost superhuman.“ —Bertrand Russel! 
! 
"Not many people managed to create a revolution 
in thought. Frege did.“ —Graham Priest ! 
Lecture on Gottlob Frege: ! 
http://www.youtube.com/watch?v=foITiYYu2bc
Please fill the feedback forms 
Dierk König 
Canoo 
mittie

Más contenido relacionado

Más de Dierk König

Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMDierk König
 
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) Dierk König
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)Dierk König
 
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...Dierk König
 
UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013Dierk König
 
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileOpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileDierk König
 

Más de Dierk König (6)

Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)
 
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
 
UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013
 
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileOpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
 

Último

Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntelliSource Technologies
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9Jürgen Gutsch
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Neo4j
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxPrakarsh -
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Projectwajrcs
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 

Último (20)

Introduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptxIntroduction-to-Software-Development-Outsourcing.pptx
Introduction-to-Software-Development-Outsourcing.pptx
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
Sustainable Web Design - Claire Thornewill
Sustainable Web Design - Claire ThornewillSustainable Web Design - Claire Thornewill
Sustainable Web Design - Claire Thornewill
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptx
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 

Frege - purely functional programming on the JVM

  • 1. Frege Purely Functional Programming on the JVM
  • 5. Frege is very different
  • 6. You would not believe just how different it is!
  • 8. Define a Function frege> times a b = a * b frege> times 3 4 12 frege> :type times Num α => α -­‐> α -­‐> α
  • 9. Define a Function frege> times a b = a * b frege> (times 3) 4 12 frege> :type times Num α => α -­‐>(α -­‐> α) no types declared function appl. left associative tell the inferred type typeclass only 1 parameter! return type is a function! thumb: „two params of same numeric type returning that type“ no comma
  • 10. Reference a Function frege> twotimes = times 2 frege> twotimes 3 6 frege> :t twotimes Int -­‐> Int
  • 11. Reference a Function frege> twotimes = times 2 frege> twotimes 3 6 frege> :t twotimes Int -­‐> Int No second argument! „Currying“, „schönfinkeling“, or „partial function application“. Concept invented by Gottlob Frege. inferred types are more specific
  • 12. Function Composition frege> twotimes (threetimes 2) 12 frege> sixtimes = twotimes . threetimes frege> sixtimes 2 frege> :t sixtimes Int -­‐> Int
  • 13. Function Composition frege> twotimes (threetimes 2) f(g(x)) 12 more about this later frege> sixtimes = twotimes . threetimes frege> sixtimes 2 (f ° g) (x) frege> :t sixtimes Int -­‐> Int
  • 14. Pattern Matching frege> times 0 (threetimes 2) 0 frege> times 0 b = 0
  • 15. Pattern Matching frege> times 0 (threetimes 2) 0 unnecessarily evaluated frege> times 0 b = 0 pattern matching shortcutting
  • 16. Lazy Evaluation frege> times 0 (length [1..]) 0 endless sequence evaluation would never stop Pattern matching and non-strict evaluation to the rescue!
  • 17. Pure Functions Java T foo(Pair<T,U> p) {…} Frege foo :: (α,β) -­‐> α What could possibly happen? What could possibly happen?
  • 18. Pure Functions Java T foo(Pair<T,U> p) {…} Frege foo :: (α,β) -­‐> α Everything! NPEs, state changes, endless loops, missile launch,… a is returned or system error
  • 20. Java -> Frege Scripting: JSR 223 Service: compile *.fr file put on javac classpath call static method simple
  • 21. Frege -> Java ! ! data Date = native java.util.Date where Declaring the messiness. native new :: () -> IO (MutableIO Date) -- new Date() native toString :: Mutable s Date -> ST s String -- d.toString() This is a key distinction between Frege and previous efforts to port Haskell to the JVM.
  • 23. Zipping addzip [] _ = [] addzip _ [] = [] addzip (x:xs) (y:ys) = (x + y : addzip xs ys )
  • 24. Zipping addzip [] _ = [] addzip _ [] = [] addzip (x:xs) (y:ys) = (x + y : addzip xs ys ) ! use as addzip [1,2,3] [1,2,3] == [2,4,6] Pattern matching feels like Prolog Why only for the (+) function? We could be more general…
  • 25. High Order Functions zipWith f [] _ = [] zipWith f _ [] = [] zipWith f (x:xs) (y:ys) = (f x y : zipWith xs ys ) ! !
  • 26. invented by Gottlob Frege High Order Functions zipWith f [] _ = [] zipWith f _ [] = [] zipWith f (x:xs) (y:ys) = (f x y : zipWith xs ys ) use as zipWith (+) [1,2,3] [1,2,3] == [2,4,6] and, yes we can now define addzip = zipWith (+)
  • 27. Fibonacci ! fib = 0: 1: addzip fib (tail fib) ! use as take 60 fib a new solution approach fib 0:1 … tail 1 … zip 1 …
  • 28. Fibonacci ! fib = 0: 1: addzip fib (tail fib) ! use as take 60 fib a new solution approach fib 0 1:1 … tail 1 … zip 2 …
  • 29. Fibonacci ! fib = 0: 1: addzip fib (tail fib) ! use as take 60 fib a new solution approach fib 0 1 1:2 … tail 2 … zip 3 …
  • 30. Fibonacci ! fib = 0: 1: addzip fib (tail fib) ! use as take 60 fib a new solution approach fib 0 1 1 2:3 … tail 3 … zip 5 …
  • 31. List Comprehension Pythagorean triples: a2 + b2 = c2! [ (m*m-­‐n*n, 2*m*n, m*m+n*n) | m <-­‐ [2..], n <-­‐ [1..m-­‐1] ] !
  • 32. List Comprehension Pythagorean triples: a2 + b2 = c2! [ (m*m-­‐n*n, 2*m*n, m*m+n*n) | m <-­‐ [2..], n <-­‐ [1..m-­‐1] ] ! endless production triples think „nested loop“
  • 33. QuickCheck -­‐-­‐ An AVL tree is balanced so that the height of the left and right subtree differ by at most 1 p_balance = forAll aTree (tree -­‐> abs tree.balance < 2) ! QuickCheck will create 500 different trees covering all corner cases in creation and validate the invariant. (from Frege source code)
  • 34. Type System Hindley-Milner more info for the programmer less work for the programmer more useful programs compile less bad programs compile http://perl.plover.com/yak/typing/ Endless recursion in merge sort detected by the type system.
  • 35. Keep the mess out! Mutable I/O Mutable Clean Computation Clean Computation Mutable Clean Computation
  • 36. Keep the mess out! Mutable I/O Mutable Clean Computation Clean Computation Mutable Clean Computation Ok, these are Monads. Be brave. Think of them as contexts that the type system propagates and makes un-escapable.
  • 37. History Java promise: „No more pointers!“! But NullPointerExceptions (?)
  • 38. Frege is different No More But state no state (unless declared) statements expressions (+ „do“ notation) interfaces type classes classes & objects algebraic data types inheritance polymorphism null references Maybe and the list goes on…
  • 39. Frege in comparison useful safe Groovy Java Frege Haskell
  • 40. Frege in comparison useful safe Groovy Java Frege Haskell concept by Simon Peyton-Jones Frege makes the Haskell spirit accessible to the Java programmer and provides a new level of safety. apply logic run computers
  • 41. Why FP matters The intellectual challenge The aesthetical enjoyment Type system and modularity benefits! It may even be useful! „An investment in knowledge always pays the best interest.“ —Benjamin Franklin
  • 42. How? http://www.frege-­‐lang.org stackoverflow „frege“ tag https://github.com/Dierk/Real_World_Frege Join the effort!
  • 43. Gottlob Frege "As I think about acts of integrity and grace, I realise that there is nothing in my knowledge that compares with Frege’s dedication to truth… ! It was almost superhuman.“ —Bertrand Russel! ! "Not many people managed to create a revolution in thought. Frege did.“ —Graham Priest ! Lecture on Gottlob Frege: ! http://www.youtube.com/watch?v=foITiYYu2bc
  • 44. Please fill the feedback forms Dierk König Canoo mittie