a type driven approach to functional design

48
A Type Driven Approach to Functional Design Michael Feathers Groupon

Upload: michaelfeathers

Post on 29-Jan-2018

1.581 views

Category:

Entertainment & Humor


0 download

TRANSCRIPT

Page 1: A Type Driven Approach to Functional Design

A Type Driven Approach to Functional Design

Michael FeathersGroupon

Page 2: A Type Driven Approach to Functional Design

A Type Driven Approach to Functional Design

Michael FeathersGroupon

(just because)

Page 3: A Type Driven Approach to Functional Design
Page 4: A Type Driven Approach to Functional Design

a

Page 5: A Type Driven Approach to Functional Design

[a]

Page 6: A Type Driven Approach to Functional Design

map :: (a -> b) -> [a] -> [b]

Page 7: A Type Driven Approach to Functional Design

map :: (a -> b) -> [a] -> [b]

map (+2) [1,2,3]

Page 8: A Type Driven Approach to Functional Design

region 7 9 “expertsexchange”

Page 9: A Type Driven Approach to Functional Design

region 7 9 “expertsexchange”

region :: Int -> Int -> String -> String

Page 10: A Type Driven Approach to Functional Design

regionFrom7 9 “expertsexchange”

regionFrom7 :: Int -> Int -> String -> String

Page 11: A Type Driven Approach to Functional Design

Hoping

Page 12: A Type Driven Approach to Functional Design

Line Break algorithm

Page 13: A Type Driven Approach to Functional Design

String -> String

Page 14: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

Page 15: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

breakTextIntoWords

Page 16: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

breakTextIntoWords

breakWordsIntoLines

Page 17: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

breakTextIntoWords

breakWordsIntoLines

joinWordsInBrokenLines

Page 18: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

breakTextIntoWords

breakWordsIntoLines

joinWordsInBrokenLines

joinBrokenLines

Page 19: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

Page 20: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

String -> [String] -> (Int -> [[String]]) -> [[String]] -> [String] -> String

Page 21: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

String -> [String] -> (Int -> [[String]]) -> [[String]] -> [String] -> String

Page 22: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

String -> [String] -> (Int -> [[String]]) -> [[String]] -> [String] -> String

Abuse!

Page 23: A Type Driven Approach to Functional Design

A Design Device

Page 24: A Type Driven Approach to Functional Design

(via Scott Ambler)

Page 25: A Type Driven Approach to Functional Design

(via Scott Ambler)

Page 26: A Type Driven Approach to Functional Design
Page 27: A Type Driven Approach to Functional Design
Page 28: A Type Driven Approach to Functional Design
Page 29: A Type Driven Approach to Functional Design
Page 30: A Type Driven Approach to Functional Design
Page 31: A Type Driven Approach to Functional Design
Page 32: A Type Driven Approach to Functional Design
Page 33: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

words

Page 34: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

words

Page 35: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

wordsbrokenLines

Page 36: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

wordsbrokenLines

wordJoinedLines

Page 37: A Type Driven Approach to Functional Design

String -> [String] -> [[String]] -> [String] -> String

wordsbrokenLines

wordJoinedLines

joinedLines

Page 38: A Type Driven Approach to Functional Design
Page 39: A Type Driven Approach to Functional Design
Page 40: A Type Driven Approach to Functional Design

Favors combinator style

Page 41: A Type Driven Approach to Functional Design

Favors combinator style

[String] -> Int

Page 42: A Type Driven Approach to Functional Design

Favors combinator style

[String] -> Int

[String] -> [Int] -> [Int] -> [Int] -> Int

(repeated types in endomorphic chain)

Page 43: A Type Driven Approach to Functional Design

Affordances

Page 44: A Type Driven Approach to Functional Design

Separate bins for your head and your notation

String -> [String] -> (Int -> [[String]]) -> [[String]] -> [String] -> String

Page 45: A Type Driven Approach to Functional Design

Concentrates on Data

Page 46: A Type Driven Approach to Functional Design

Concentrates on Data

..in naming

Page 47: A Type Driven Approach to Functional Design

Favors combinator style

Staying in the same shape is the easiest way to get from here to there

Page 48: A Type Driven Approach to Functional Design

Thank you