![Page 1: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/1.jpg)
Purely functional programming - the red pillJFokus Tutorial 2016
![Page 2: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/2.jpg)
Dierk König canoo
mittie
![Page 3: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/3.jpg)
Dreaming of code
![Page 4: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/4.jpg)
Why do we care?a=1
b=2
c=b
b=a
a=c
1
1 2
1 2
2
1
1
22
1 2
time1time2time3
place1 place2 place3
![Page 5: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/5.jpg)
Operational Reasoninga=1
b=2
c=b
b=a
a=c
1
1 2
1 2 2
1 1 2
2 1 2
time1time2time3
place1 place2 place3
We need a debugger!
![Page 6: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/6.jpg)
Using functionsa=1
b=2
1
1 2
![Page 7: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/7.jpg)
Using functionsa=1
b=2
1
1 2
2 1
swap(a,b)=(b,a)
![Page 8: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/8.jpg)
Let’s just program without
assignments or statements!
![Page 9: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/9.jpg)
Developer Discipline
Pure Functional Language
![Page 10: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/10.jpg)
Online REPL try.frege-lang.org
![Page 11: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/11.jpg)
Define a Functionfrege>timesab=a*b
frege>times23
6
frege>:typetimes
Numα=>α->α->α
![Page 12: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/12.jpg)
Define a Functionfrege>timesab=a*b
frege>(times2)3
6
frege>:typetimes
Numα=>α->(α->α)
no types declared
function appl. left associative
typeclass constraint
only 1 parameter!
return type is a function!
thumb: „two params of same numeric type returning that type“
no comma
![Page 13: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/13.jpg)
Reference a Functionfrege>twotimes=times2
frege>twotimes3
6
frege>:ttwotimes
Int->Int
![Page 14: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/14.jpg)
Reference a Functionfrege>twotimesx=times2x
frege>twotimes3
6
frege>:ttwotimes
Int->Int
No second arg!
„Currying“, „schönfinkeling“, or „partial function
application“. Concept invented by
Gottlob Frege.
inferred types are more specific
![Page 15: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/15.jpg)
Function Compositionfrege>sixx=twotimes(threetimesx)
frege>sixx=(twotimes.threetimes)x
frege>six=twotimes.threetimes
frege>six2
12
![Page 16: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/16.jpg)
Function Compositionfrege>sixx=twotimes(threetimesx)
frege>sixx=(twotimes.threetimes)x
frege>six=twotimes.threetimes
frege>six2
12
f(g(x))
(f ° g) x
f ° g
![Page 17: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/17.jpg)
Pattern Matchingfrege>times0(threetimes2)
0
frege>times0b=0
![Page 18: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/18.jpg)
Pattern Matchingfrege>times0(threetimes2)
0
frege>times0b=0
unnecessarily evaluated
shortcuttingpattern matching
![Page 19: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/19.jpg)
Lazy Evaluationfrege>times0(length[1..])
0endless sequence
evaluation would never stop
Pattern matching and non-strict evaluation
to the rescue!
![Page 20: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/20.jpg)
Pure FunctionsJava
Tfoo(Pair<T,U>p){…}
Frege
foo::(α,β)->α
What could possibly happen?
What could possibly happen?
![Page 21: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/21.jpg)
Pure FunctionsJava
Tfoo(Pair<T,U>p){…}
Frege
foo::(α,β)->α
Everything! State changes,
file or db access, missile launch,…
a is returned
![Page 22: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/22.jpg)
can be cached (memoized) can be evaluated lazily can be evaluated in advance can be evaluated concurrently can be eliminated in common subexpressions
can be optimized
Pure Functions
![Page 23: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/23.jpg)
Is my method pure?
Let the type system find out!
![Page 24: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/24.jpg)
Magic (?)Thinkofagenericfunction
f::[a]->[a]
andanyspecificfunction
g::a->b
![Page 25: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/25.jpg)
Magic (?)
[a] [a]
[b] [b]
f
f
map g map g
![Page 26: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/26.jpg)
Magic (?)
[1,2,3] [3,2,1]
[2,4,6] [6,4,2]
reverse
reverse
map (*2) map (*2)
Commutative square of natural transformations.
![Page 27: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/27.jpg)
Robust RefactoringChanging the order of operationsRequires purity.100% safe if the type system can detect natural transformations
Applied Category Theorycredits: Phil Wadler, Tech Mesh 2012 - Faith, Evolution, and Programming Languages
![Page 28: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/28.jpg)
QuickCheckimportTest.QuickCheckf=reverseg=(*2)
commutativity=property(\xs->mapg(fxs)==f(mapgxs))
![Page 29: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/29.jpg)
Java Interoperability
Do not mix OO and FP,
combine them!
![Page 30: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/30.jpg)
Java -> FregeFrege compiles Haskell to Java source and byte code.
Just call that.
You can get help by using the :java command in the REPL.
![Page 31: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/31.jpg)
pure native encode java.net.URLEncoder.encode :: String -> String encode “Dierk König“
native millis java.lang.System.currentTimeMillis :: () -> IO Long millis () millis () past = millis () - 1000
Does not compile!
Frege -> Java
This is a key distinction between Frege and other JVM languages!
even Java can be pure
![Page 32: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/32.jpg)
allows calling Java but never unprotected!
is explicit about effects just like Haskell
Frege
Prerequisite to safe concurrency and deterministic parallelism!
![Page 33: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/33.jpg)
Type SystemGlobal type inference
More safety and less work for the programmer
You don’t need to specify any types at all! But sometimes you do for clarity.
![Page 34: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/34.jpg)
Mutable I/O
Mutable
Mutable
Keep the mess out!
Pure Computation
Pure Computation
Pure Computation
![Page 35: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/35.jpg)
Mutable I/O
Mutable
Mutable
Keep the mess out!
Pure Computation
Pure Computation
Pure Computation
Ok, these are Monads. Be brave. Think of them as contexts that the type system propagates and makes un-escapable.
Thread-safe by design! Checked
by compiler
![Page 36: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/36.jpg)
JavaJava
Java
Service Based Design
Frege
Frege
Frege
A typical integration option: use Frege code for services
![Page 37: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/37.jpg)
Some Cool Stuff
![Page 38: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/38.jpg)
Zippingaddzip[]_=[]addzip_[]=[]
addzip(x:xs)(y:ys)=(x+y:addzipxsys)
![Page 39: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/39.jpg)
Zippingaddzip[]_=[]addzip_[]=[]
addzip(x:xs)(y:ys)=(x+y:addzipxsys)
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…
![Page 40: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/40.jpg)
High Order FunctionszipWithf[]_=[]zipWithf_[]=[]
zipWithf(x:xs)(y:ys)=(fxy:zipWithfxsys)
![Page 41: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/41.jpg)
High Order FunctionszipWithf[]_=[]zipWithf_[]=[]
zipWithf(x:xs)(y:ys)=(fxy:zipWithxsys)
use as zipWith(+)[1,2,3][1,2,3]==[2,4,6]
and, yes we can now define addzip= zipWith(+)
invented by Gottlob Frege
![Page 42: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/42.jpg)
Fizzbuzzhttp://c2.com/cgi/wiki?FizzBuzzTest
https://dierk.gitbooks.io/fregegoodness/ chapter 8 „FizzBuzz“
![Page 43: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/43.jpg)
Fizzbuzz ImperativepublicclassFizzBuzz{publicstaticvoidmain(String[]args){for(inti=1;i<=100;i++){if(i%15==0{System.out.println(„FizzBuzz");}elseif(i%3==0){System.out.println("Fizz");}elseif(i%5==0){System.out.println("Buzz");}else{System.out.println(i);}}}}
![Page 44: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/44.jpg)
Fizzbuzz Logicalfizzes=cycle["","","fizz"]buzzes=cycle["","","","","buzz"]pattern=zipWith(++)fizzesbuzzesnumbers=mapshow[1..]fizzbuzz=zipWithmaxpatternnumbers
main_=for(take100fizzbuzz)println
![Page 45: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/45.jpg)
Fizzbuzz ComparisonImperative Logical
Conditionals 4 0
Operators 7 1
Nesting level 3 0
Sequencing sensitive transparent
Maintainability - - - +
Incremental development - +++
![Page 46: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/46.jpg)
Fibonacci
fib=0:1:addzipfib(tailfib)
use as take60fib
a new solution approach
fib0:1…tail1…zip1…
![Page 47: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/47.jpg)
Fibonacci
fib=0:1:addzipfib(tailfib)
use as take60fib
a new solution approach
fib01:1…tail1…zip2…
![Page 48: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/48.jpg)
Fibonacci
fib=0:1:addzipfib(tailfib)
use as take60fib
a new solution approach
fib011:2…tail2…zip3…
![Page 49: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/49.jpg)
Fibonacci
fib=0:1:addzipfib(tailfib)
use as take60fib
a new solution approach
fib0112:3…tail3…zip5…
![Page 50: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/50.jpg)
List ComprehensionPythagorean triples: a2 + b2 = c2
pythn=[
(x,y,z)
|x<-[1..n],y<-[1..n],z<-[1..n],
x*x+y*y==z*z
]
![Page 51: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/51.jpg)
List ComprehensionPythagorean triples: a2 + b2 = c2
pythn=[
(x,y,z)
|x<-[1..n],y<-[1..n],z<-[1..n],
x*x+y*y==z*z
]
select from
where
„brute force“ or „executable specification“. A more efficient solution:
![Page 52: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/52.jpg)
List ComprehensionPythagorean triples: a2 + b2 = c2
[(m*m-n*n,2*m*n,m*m+n*n)
|m<-[2..],n<-[1..m-1]
]
endless production think „nested loop“
„select“ functions
dynamic „from“
empty „where“
![Page 53: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/53.jpg)
HistoryJava promise: „No more pointers!“
But NullPointerExceptions (?)
![Page 54: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/54.jpg)
Frege is differentNo More But
state no state (unless declared)statements expressions (+ „do“ notation)assignments definitionsvariables ST monad as „agent“interfaces type classesclasses & objects algebraic data typesinheritance parametric polymorphismnull references MaybeNullPointerExceptions Bottom, error
![Page 55: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/55.jpg)
Frege in comparison
practical
robust
JavaGroovy
FregeHaskell
![Page 56: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/56.jpg)
Frege in comparison
JavaGroovy
FregeHaskell
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
practical
robust
![Page 57: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/57.jpg)
Unique in FregeGlobal type inference requires a purely functional language (only expressions and parametric polymorphism) Purity by default effects are explicit in the type systemLaziness by defaultValues are always immutable Guarantees extend into Java calls
![Page 58: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/58.jpg)
Why FregeRobustness under parallel execution Robustness under composition Robustness under incrementsRobustness under refactoring
Enables local and equational reasoning
Best way to learn FP
![Page 59: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/59.jpg)
Why FP mattersEnabling incremental development www.canoo.com/blog/fp1 Brush up computational fundamentals
„An investment in knowledge always pays the best interest.“
—Benjamin Franklin
![Page 60: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/60.jpg)
Why Frege
it is just a pleasure to work with
![Page 61: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/61.jpg)
![Page 62: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/62.jpg)
How?http://www.frege-lang.org@fregelangstackoverflow „frege“ tagedX FP101 MOOC
![Page 63: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/63.jpg)
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. Twice.“ —Graham Priest Lecture on Gottlob Frege: http://www.youtube.com/watch?v=foITiYYu2bc
![Page 64: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/64.jpg)
FGALanguage level is Haskell Report 2010.Yes, performance is roughly ~ Java.Yes, the compiler is reasonably fast.Yes, we have an Eclipse Plugin.Yes, Maven/Gradle/etc. integration.Yes, we have HAMT (aka HashMap). Yes, we have QuickCheck (+shrinking) Yes, STM is almost finished.
![Page 65: Purely functional programming - the red pill · frege> times a b = a * b frege>(times 2)3 6 frege> :type times Num α => α ->(α -> α) no types declared function appl. left associative](https://reader030.vdocuments.us/reader030/viewer/2022041014/5ec5a4d52ad13414087cd349/html5/thumbnails/65.jpg)
How it goes onPractical project work github.com/Dierk/fregeTutorial.git
Purely functional turtle graphics
Game / Web
Software Transactional Memory