Functional Programming in 40 minutes @russolsen
Functional Programming in 40 minutes @russolsen
Functional Programming
Functional Programming Clojure spin
Functional Programming 40 Minutes?
What is it? What's it like? Does it work?
What is it? What's it like? Does it work?
FORGET Everything You Know About Programming
What Do You Know?
Names Name = Value Ifs Iteration Procedures
Strings Numerics Booleans Indentation Names Name = Value Ifs Iteration Procedures
Arrays Hashes Namespaces Strings Numerics Booleans Indentation Names Name = Value Ifs Iteration Procedures
Inheritance Classes Methods Arrays Hashes Namespaces Strings Numerics Booleans Indentation Names Name = Value Ifs Iteration Procedures
Programs Inheritance Classes Methods Arrays Hashes Namespaces Strings Numerics Booleans Indentation Names Name = Value Ifs Iteration Procedures
FORGET REALLY? Everything You Know About Programming
Functional Programming
Refactor Everything You Know About Programming
It Works But...
Mess
What About Programming?
During the type erasure process, the Java compiler erases all type parameters and replaces each with its first bound if the type parameter is bounded, or Object if the type parameter is unbounded. https://docs.oracle.com/javase/tutorial/java/generics/genTypes.html
During the type erasure process, the Java compiler erases all type parameters and replaces each with its first bound if the type parameter is bounded, or Object if the type parameter is unbounded.
Protected methods: a protected method is similar to a private method, with the addition that it can be called with, or without, an explicit receiver, but that receiver is always self (it’s defining class) or an object that inherits from self . https://medium.com/@tjoye20/ruby-access-control-basics-public-vs-private-vs-protected- methods-7788b26e04a7
A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions. https://www.tutorialspoint.com/cplusplus/cpp_friend_functions.htm
Programs Inheritance Classes Methods Arrays Hashes Namespaces Strings Numerics Booleans Indentation Names Name = Value Ifs Iteration Procedures
Messy?
Programs Namespaces Arrays Hashes Strings Numerics Booleans Indentation Name = Names Ifs Iteration Value
f(x)
f(x) 2 4 1 6 8 3 4 2 5 10
2 4 1 6 8 3 4 2 5 10
Methods Procedures Subroutines Functions
6 3 5 10
6 3 42 5 10 ??
6 3 5 10
6 3 10 5
A Thing f(x)
A Thing I Can Make f(x)
f(x)
1st Class
Look at Input Produce Output
No Side E ff ects
x = ['a','b','c'] y = a(x) x = ?
x = ['a','b','c'] c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * y = floor(b(x)) + 16 * a(x) - ceil(g(x) - c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) x = ?
Programs f(x) Namespaces Arrays Hashes Strings Numerics Booleans Indentation Name = Names Ifs Iteration Value
Problem
a b c
a b c
a Q c
x = ['a','b','c'] c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * y = floor(b(x)) + 16 * a(x) - ceil(g(x) - c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) x = ?
t = c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x) x[2] = 'Q' y = t + c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
t = c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x) x[2] = 'Q' y = t + c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
Immutable
a b c a Q c
Problem
Copies Copies Copies
a b c d e f g h i j k l m n o p q r s t u v w x y z !
m n a b c d e f g h i j k l o p q r s t u v w x y z ! m Q a b c d e f g h i j k l o p q r s t u v w x y z !
Persistent Data Structures
a b c d e f g h i j k l m n o p q r s t u v w x y z !
a b c d e f g h i j k l m n o p q r s t u v w x y z !
m Q o
Q m X o
Q m X o
Q a b c d e f g h i j k l m X o p q r s t u v w x y z !
3
3
Programs f(x) Namespaces Arrays* Hashes* Strings Numerics Booleans Indentation Name = Names Ifs Iteration Value
Problem
Side E ff ects
SIDE EFFECTS Russ Olsen russ@russolsen.com
EFFECTS Russ Olsen russ@russolsen.com
Atoms 57
Atoms f(x) 57
Atoms f(x) 58
Atoms f(x) 59 g(x)
Atoms f(x) 59 g(x) g(x)
Agents/Actors f(x) some_code(queue) g(x)
Recommend
More recommend