Top Banner
Make your programs Free Pawel Szulc @rabbitonweb
37

Make your programs free.

Jan 22, 2017

Download

Software

Pawel Szulc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Make your programs free.

Make your programs Free

Pawel Szulc@rabbitonweb

Page 2: Make your programs free.
Page 3: Make your programs free.

Outline

Page 4: Make your programs free.

Outline

❏ What is a Free monad, how to use it?

Page 5: Make your programs free.

Outline

❏ What is a Free monad, how to use it?❏ Notion of the concept, [almost] no mechanics!

Page 6: Make your programs free.

Outline

❏ What is a Free monad, how to use it?

Page 7: Make your programs free.

Outline

❏ What is a Free monad, how to use it?❏ Q&A from the Internet

Page 8: Make your programs free.

Outline

❏ What motivates usage of a Free monad?❏ What is a Free monad, how to use it?❏ Q&A from the Internet

Page 9: Make your programs free.

What is Functional Programming?

Page 10: Make your programs free.

What is Functional Programming?

● no assignment statements

Page 11: Make your programs free.

What is Functional Programming?

● no assignment statements● no variables

Page 12: Make your programs free.

What is Functional Programming?

● no assignment statements● no variables● once given a value, never change

Page 13: Make your programs free.

What is Functional Programming?

● no assignment statements● no variables● once given a value, never change● no side-effects at all

Page 14: Make your programs free.

What is Functional Programming?

● no assignment statements● no variables● once given a value, never change● no side-effects at all

Page 15: Make your programs free.

What is Functional Programming?

● no assignment statements● no variables● once given a value, never change● no side-effects at all

“The functional programmer sounds rather like a mediæval monk, denying himself the pleasures of life in the hope that it will make him virtuous.”

Page 16: Make your programs free.

We strive for modularity

Page 17: Make your programs free.

Divide & conquer

➔ Microservices➔ SOA➔ OOP

Page 18: Make your programs free.

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

Page 19: Make your programs free.

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

Page 20: Make your programs free.

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

“COMPLEXITY CONTROLLED BY HIERARCHICAL ORDERING OF FUNCTION AND VARIABILITY” by Edsger W. Dijkstra

Page 21: Make your programs free.

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

“COMPLEXITY CONTROLLED BY HIERARCHICAL ORDERING OF FUNCTION AND VARIABILITY” by Edsger W. Dijkstra

http://homepages.cs.ncl.ac.uk/brian.randell/NATO/nato1968.PDF

Page 22: Make your programs free.

input f(input): output output g(input): output output

Page 23: Make your programs free.

h = g . f

input f(input): output output g(input): output output

Page 24: Make your programs free.

h = g . f

input f(input): output output g(input): output output

Page 25: Make your programs free.
Page 26: Make your programs free.
Page 27: Make your programs free.
Page 28: Make your programs free.

https://xkcd.com/1312/

Page 29: Make your programs free.

Free Monads!

Page 30: Make your programs free.

Free[S, A]

Page 31: Make your programs free.

Free[S, A]This is the program

Page 32: Make your programs free.

Free[S, A] This is the language

Page 33: Make your programs free.

Free[S, A]This is the type of a value it will produce (once it is run)

Page 34: Make your programs free.

Let’s see it in action!(aka Demo)

https://github.com/rabbitonweb/make-your-programs-free

Page 35: Make your programs free.

Resources

● Stackless Scala With Free Monads○ http://blog.higher-order.com/assets/trampolines.pdf

● Data types a la carte○ http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf

● Composable application architecture with reasonably priced monads○ https://www.youtube.com/watch?v=M258zVn4m2M

● Why the free monad isn’t free ○ https://www.youtube.com/watch?v=U0lK0hnbc4U (with disclaimer)

● Move Over Free Monads: Make Way for Free Applicatives!○ https://www.youtube.com/watch?v=H28QqxO7Ihc

● http://perevillega.com/understanding-free-monads ● http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html

Page 36: Make your programs free.

But I want to see a real world example!

https://github.com/quasar-analytics/quasar