Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Functional Programming Patterns
Search
Robin Palotai
September 18, 2012
Programming
7
470
Functional Programming Patterns
A short enumeration of selected patters occuring in FP.
Robin Palotai
September 18, 2012
Tweet
Share
More Decks by Robin Palotai
See All by Robin Palotai
A subjective on Functional Programming
ron
4
330
SwfControl
ron
0
28
Other Decks in Programming
See All in Programming
Fragment Composition of GraphQL
quramy
7
1k
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
210
Elm Form Validation
bkuhlmann
0
510
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1.2k
Hanami and htmx
bkuhlmann
0
210
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
540
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.3k
雑に思考を整理する技術と効能
konifar
60
29k
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
7
1k
新宿ダンジョンを可視化してみた
satoshi7190
2
270
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
870
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
648
58k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
The Mythical Team-Month
searls
216
42k
Art, The Web, and Tiny UX
lynnandtonic
289
19k
Faster Mobile Websites
deanohume
299
30k
Statistics for Hackers
jakevdp
789
220k
Designing on Purpose - Digital PM Summit 2013
jponch
110
6.5k
In The Pink: A Labor of Love
frogandcode
138
21k
How GitHub (no longer) Works
holman
304
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
244
20k
A better future with KSS
kneath
231
16k
Transcript
Functional Programming Patterns
1st class functions Functions are values too. They have type.
Can be assigned to variables. f: a b → g: (a, b) c → input type output type → multiple arguments
Higher order funs A higher order function is a function
that takes other functions as argument. h: ([a], a b) [b] → → list elem mapper Strategy pattern-like
Currying f: (a, b) c → f: a b c
→ → f: a (b c) → → curried form right-associative Factory pattern-like
Pure Functions Referential transparency – expression replaceable with its value
without changing program semantics. easy to reason about optimizable
Immutability Values are constructed and then never modified. persistent collections
tuples and Lists pair: (a, b) 3-tuple: (a, b, c)
1 :: 2 :: 3 :: Nil [1, [2, [3, []]]] heterogeneous fixed lengthc homogeneous unbounded length
Transform Recursion is low-level flow control. Usages can be abstracted.
Tell what, not how. map, filter, fold
Algebraic Data Types data List a = Cons a (List
a) | Nil data Tree a = Node (Tree a) a (Tree a) | Empty
Functor A functor is a computational context. Map applies a
normal function to a value in a context. map: f a (a b) f b → → → F<A> (A B) F<B> → → → fmap
Monad point: a f a → flatMap: f a (a
f b) f → → → b A context with richer operations. pure, return bind
Option Nulls made explicit. No more NPE. data Option a
= Some a | None orElse: Opt a Opt a Opt a → → getOrElse: Opt a a a → → Monad
Either data Either a b = Left a | Right
b Often used for error handling, where error is on the left, success on the right. Monad for a fixed a
Future Promise / Future is a context, where the contained
computation may execute concurrently. Used to compose async computations without blocking. Monad
Typeclasses A typeclass describes a contract. A typeclass instance describes
how a given data type fulfills that contract. Like an Adapter, but more versatile.
Semigroup Monoid , Semigroup defines addition. Monoid is semigroup with
an identity element. Pops all over your code!
Foldable A foldable provides means for stateful traversal. foldLeft: f
a b (b a b) b → → → → → Nice cooperation with Monoids
Extra stuff Applicative functors, Monad transformers, Relational databases, Linear logic,
IO, DI, Logging, Total FP, Actors, ...
Thx