make your programs free

37
Make your programs Free Pawel Szulc @rabbitonweb

Upload: pawel-szulc

Post on 22-Jan-2017

143 views

Category:

Software


1 download

TRANSCRIPT

Make your programs Free

Pawel Szulc@rabbitonweb

Outline

Outline

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

Outline

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

Outline

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

Outline

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

Outline

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

What is Functional Programming?

What is Functional Programming?

● no assignment statements

What is Functional Programming?

● no assignment statements● no variables

What is Functional Programming?

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

What is Functional Programming?

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

What is Functional Programming?

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

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.”

We strive for modularity

Divide & conquer

➔ Microservices➔ SOA➔ OOP

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

Divide & conquer

SOFTWARE ENGINEERING NATO SCIENCE COMMITTEE Garmisch

Germany, 7th to 11th October 1968

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

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

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

h = g . f

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

h = g . f

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

https://xkcd.com/1312/

Free Monads!

Free[S, A]

Free[S, A]This is the program

Free[S, A] This is the language

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

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

https://github.com/rabbitonweb/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

But I want to see a real world example!

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