Slide 1

Slide 1 text

Manuel M T Chakravarty (Applicative & Tweag I/O) Gabriele Keller (UNSW Sydney) Demystifying Functional Programming And what that means for learning & teaching mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 2

Slide 2 text

Structured Programming (1960s)

Slide 3

Slide 3 text

Object-Oriented Programming (70s/80s)

Slide 4

Slide 4 text

Functional Programming

Slide 5

Slide 5 text

Functional Programming Too academic Impractical Too complicated Inefficient Not for the average developer

Slide 6

Slide 6 text

Diffusion of Innovation [Everett Rogers 1962]

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

How do we get them on board?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

There is still time to submit proposals (deadline 18 March)!

Slide 14

Slide 14 text

There is still time to submit proposals (deadline 18 March)!

Slide 15

Slide 15 text

“How do we teach FP to the early majority as opposed to early adopters (and innovators).”

Slide 16

Slide 16 text

http://learninghaskell.com

Slide 17

Slide 17 text

Advise to The Innovator

Slide 18

Slide 18 text

“Liberation from the tyranny of syntax: focus on concepts instead of language constructs.”

Slide 19

Slide 19 text

“Liberation from the tyranny of syntax: focus on concepts instead of language constructs.” —Felleisen et al, The Structure and Interpretation of the Computer Science Curriculum

Slide 20

Slide 20 text

Beware of Historical Explanations

Slide 21

Slide 21 text

Beware of Historical Explanations Category Theory

Slide 22

Slide 22 text

Beware of Historical Explanations Category Theory Formal Semantics

Slide 23

Slide 23 text

Beware of Historical Explanations Category Theory Formal Semantics Functional Programming

Slide 24

Slide 24 text

Beware of Historical Explanations “A monad is a monoid in the category of endofunctors.” Category Theory Formal Semantics Functional Programming

Slide 25

Slide 25 text

Beware of Historical Explanations “A monad is a monoid in the category of endofunctors.” Category Theory Formal Semantics Functional Programming We need explanations that can stand on their own

Slide 26

Slide 26 text

Mindset of The Early Adopter

Slide 27

Slide 27 text

Examples First

Slide 28

Slide 28 text

Examples First Why?

Slide 29

Slide 29 text

Examples First Why? Example #1 Example #2 Example #n ộ

Slide 30

Slide 30 text

Examples First Why? Example #1 Example #2 Example #n ộ Problem statement

Slide 31

Slide 31 text

Examples First Why? Example #1 Example #2 Example #n ộ Problem statement Example solution ộ

Slide 32

Slide 32 text

Examples First Why? Example #1 Example #2 Example #n ộ Problem statement General concept Example solution ộ

Slide 33

Slide 33 text

Math Later

Slide 34

Slide 34 text

Math Later “If math is useful to a functional programmer, functional programming must be able to motivate math.”

Slide 35

Slide 35 text

Math Later “If math is useful to a functional programmer, functional programming must be able to motivate math.”

Slide 36

Slide 36 text

But the Jargon is Here to Stay

Slide 37

Slide 37 text

But the Jargon is Here to Stay Burrito Warm fuzzy thing Workflow Computation builder Kleisli triple

Slide 38

Slide 38 text

But the Jargon is Here to Stay Burrito Warm fuzzy thing Workflow Computation builder Kleisli triple Monad

Slide 39

Slide 39 text

Teaching The Early Majority

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Examples first Generalise & abstract only after demonstrating a need

Slide 42

Slide 42 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways

Slide 43

Slide 43 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds

Slide 44

Slide 44 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 45

Slide 45 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 46

Slide 46 text

Examples first Generalise & abstract only after demonstrating a need

Slide 47

Slide 47 text

The Trouble with Recursion

Slide 48

Slide 48 text

The Trouble with Recursion fix :: (a -> a) -> a fix f = let x = f x in x Simple. Elegant. Powerful.

Slide 49

Slide 49 text

The Trouble with Recursion fix :: (a -> a) -> a fix f = let x = f x in x Simple. Elegant. Powerful. And utterly confusing…

Slide 50

Slide 50 text

How does it work? How can I use it to solve a given problem?

Slide 51

Slide 51 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0

Slide 52

Slide 52 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 natSum 3 = 3 + 2 + 1 + 0 natSum 4 = 4 + 3 + 2 + 1 + 0 natSum 5 = 5 + 4 + 3 + 2 + 1 + 0 ⋮

Slide 53

Slide 53 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 natSum 3 = 3 + 2 + 1 + 0 natSum 4 = 4 + 3 + 2 + 1 + 0 natSum 5 = 5 + 4 + 3 + 2 + 1 + 0 ⋮ we can reuse natSum 4

Slide 54

Slide 54 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum 1 = 1 + natSum 0 natSum 2 = 2 + natSum 1 natSum 3 = 3 + natSum 2 natSum 4 = 4 + natSum 3 natSum 5 = 5 + natSum 4 ⋮

Slide 55

Slide 55 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum 1 = 1 + natSum 0 natSum 2 = 2 + natSum 1 natSum 3 = 3 + natSum 2 natSum 4 = 4 + natSum 3 natSum 5 = 5 + natSum 4 ⋮ from here on all the same with different numbers

Slide 56

Slide 56 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum n = n + natSum (n - 1)

Slide 57

Slide 57 text

First Recursion Example natSum n 㱺 n + (n-1) + ⋯ + 2 + 1 + 0 natSum 0 = 0 natSum n = n + natSum (n - 1) use variable instead of unbound sequence

Slide 58

Slide 58 text

natSum 0 = 0 natSum n = n + natSum (n - 1)

Slide 59

Slide 59 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)

Slide 60

Slide 60 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4

Slide 61

Slide 61 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))

Slide 62

Slide 62 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)

Slide 63

Slide 63 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))

Slide 64

Slide 64 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))

Slide 65

Slide 65 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))

Slide 66

Slide 66 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))

Slide 67

Slide 67 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))        㱺 5 + (4 + (3 + (2 + (1 + natSum (1 - 1)))))

Slide 68

Slide 68 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))        㱺 5 + (4 + (3 + (2 + (1 + natSum (1 - 1)))))        㱺 5 + (4 + (3 + (2 + (1 + natSum 0))))

Slide 69

Slide 69 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))        㱺 5 + (4 + (3 + (2 + (1 + natSum (1 - 1)))))        㱺 5 + (4 + (3 + (2 + (1 + natSum 0))))        㱺 5 + (4 + (3 + (2 + (1 + 0))))

Slide 70

Slide 70 text

natSum 0 = 0 natSum n = n + natSum (n - 1) natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))        㱺 5 + (4 + (3 + (2 + (1 + natSum (1 - 1)))))        㱺 5 + (4 + (3 + (2 + (1 + natSum 0))))        㱺 5 + (4 + (3 + (2 + (1 + 0))))        㱺 15 natSum 5  㱺 5 + natSum (5 - 1)        㱺 5 + natSum 4        㱺 5 + (4 + natSum (4 - 1))        㱺 5 + (4 + natSum 3)        㱺 5 + (4 + (3 + natSum (3 - 1)))        㱺 5 + (4 + (3 + natSum 2))        㱺 5 + (4 + (3 + (2 + natSum (2 - 1))))        㱺 5 + (4 + (3 + (2 + natSum 1)))        㱺 5 + (4 + (3 + (2 + (1 + natSum (1 - 1)))))        㱺 5 + (4 + (3 + (2 + (1 + natSum 0))))        㱺 5 + (4 + (3 + (2 + (1 + 0))))        㱺 15

Slide 71

Slide 71 text

Example-Driven Development Illustrates the concept (here recursion)

Slide 72

Slide 72 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code)

Slide 73

Slide 73 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion

Slide 74

Slide 74 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion Higher-order functions

Slide 75

Slide 75 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion Higher-order functions Parametric polymorphism

Slide 76

Slide 76 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion Higher-order functions Parametric polymorphism Type classes

Slide 77

Slide 77 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion Higher-order functions Parametric polymorphism Type classes Categorial structures

Slide 78

Slide 78 text

Example-Driven Development Illustrates the concept (here recursion) Provides a concrete problem solving strategy (to get students started on their own code) Recursion Higher-order functions Parametric polymorphism Type classes Categorial structures and more

Slide 79

Slide 79 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 80

Slide 80 text

Teach design patterns FP abstractions are used in various idiomatic ways

Slide 81

Slide 81 text

allSquares :: Num a => [a] -> [a] allSquares [] = [] allSquares (x : xs) = x * x : allSquares xs

Slide 82

Slide 82 text

allSquares :: Num a => [a] -> [a] allSquares [] = [] allSquares (x : xs) = x * x : allSquares xs allToUpper :: String -> String allToUpper [] = [] allToUpper (chr : restString) = toUpper chr : allToUpper restString

Slide 83

Slide 83 text

allSquares :: Num a => [a] -> [a] allSquares [] = [] allSquares (x : xs) = x * x : allSquares xs allToUpper :: String -> String allToUpper [] = [] allToUpper (chr : restString) = toUpper chr : allToUpper restString

Slide 84

Slide 84 text

allSquares :: Num a => [a] -> [a] allSquares [] = [] allSquares (x : xs) = x * x : allSquares xs allToUpper :: String -> String allToUpper [] = [] allToUpper (chr : restString) = toUpper chr : allToUpper restString recursiveFunction [] = [] recursiveFunction (x : xs) = doSomethingWith x : recursiveFunction xs

Slide 85

Slide 85 text

Computational Design Patterns Illustrates a computational idiom (here map-like recursion)

Slide 86

Slide 86 text

Computational Design Patterns Illustrates a computational idiom (here map-like recursion) Provides learners with concrete guidance on how to get started

Slide 87

Slide 87 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 88

Slide 88 text

Tight feedback loop Examples, stepwise evaluation, playgrounds

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Examples first Generalise & abstract only after demonstrating a need Teach design patterns FP abstractions are used in various idiomatic ways Tight feedback loop Examples, stepwise evaluation, playgrounds Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 92

Slide 92 text

Visualisation can be an effective tool Pure computations lend themselves to visualisation

Slide 93

Slide 93 text

Pythagorean Trees

Slide 94

Slide 94 text

Pythagorean Trees

Slide 95

Slide 95 text

Pythagorean Trees

Slide 96

Slide 96 text

Pythagorean Trees

Slide 97

Slide 97 text

Pythagorean Trees

Slide 98

Slide 98 text

Pythagorean Trees

Slide 99

Slide 99 text

Pythagorean Trees

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Properties Type Systems

Slide 104

Slide 104 text

Are types restraints?

Slide 105

Slide 105 text

Types are a design tool!

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

https://speakerdeck.com/mchakravarty/a-type-is-worth-a-thousand-tests YOW! Connected 2016, Melbourne

Slide 108

Slide 108 text

“Doesn’t static typing hinder experimentation as you have to get everything right, before you can run it?”

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

Improving Our Tools

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

Is this the best we can do?

Slide 114

Slide 114 text

http://worrydream.com

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

Haskell for Mac

Slide 117

Slide 117 text

Haskell for Mac

Slide 118

Slide 118 text

Swift Playgrounds (iPad)

Slide 119

Slide 119 text

mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 120

Slide 120 text

natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 ⋮ Examples first mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 121

Slide 121 text

natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 ⋮ Examples first recursiveFunction [] = [] recursiveFunction (x : xs) = doSomethingWith x : recursiveFunction xs Teach design patterns mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 122

Slide 122 text

natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 ⋮ Examples first recursiveFunction [] = [] recursiveFunction (x : xs) = doSomethingWith x : recursiveFunction xs Teach design patterns Tight feedback loop & visualisation mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 123

Slide 123 text

natSum 0 = 0 natSum 1 = 1 + 0 natSum 2 = 2 + 1 + 0 ⋮ Examples first recursiveFunction [] = [] recursiveFunction (x : xs) = doSomethingWith x : recursiveFunction xs Teach design patterns Tight feedback loop & visualisation http://learninghaskell.com mchakravarty TacticalGrace justtesting.org haskellformac.com

Slide 124

Slide 124 text

Thank you!

Slide 125

Slide 125 text

Image Attribution https://pixabay.com/photo-1246043/ https://commons.wikimedia.org/wiki/File:Diffusion_of_ideas.svg https://web.archive.org/web/20140722064822/http://haskell.cs.yale.edu/people/paul-hudak/ https://commons.wikimedia.org/wiki/File:Robert_Harper.jpg https://commons.wikimedia.org/wiki/File:Rich_Hickey.jpg https://commons.wikimedia.org/wiki/File:Alan_Kay_(3097597186).jpg https://commons.wikimedia.org/wiki/File:Edsger_Wybe_Dijkstra.jpg https://harc.github.io/seymour-live2017/ https://pixabay.com/photo-2536159/ https://pixabay.com/photo-1218797/ https://pixabay.com/photo-3195378/ https://pixabay.com/photo-2245832/ https://commons.wikimedia.org/wiki/File:Eugenio_Moggi.jpg https://commons.wikimedia.org/wiki/File:Wadler2.JPG https://commons.wikimedia.org/wiki/File:Handcuffs01_2008-07-27.jpg https://commons.wikimedia.org/wiki/File:Set_square_Geodreieck.svg https://www.flickr.com/photos/provisions/7986149891/