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
480
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
340
SwfControl
ron
0
40
Other Decks in Programming
See All in Programming
アセットのコンパイルについて
ojun9
0
120
モバイルアプリからWebへの横展開を加速した話_Claude_Code_実践術.pdf
kazuyasakamoto
0
320
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
120
さようなら Date。 ようこそTemporal! 3年間先行利用して得られた知見の共有
8beeeaaat
3
1.4k
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
270
rage against annotate_predecessor
junk0612
0
170
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
260
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.3k
RDoc meets YARD
okuramasafumi
4
170
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
440
今から始めるClaude Code入門〜AIコーディングエージェントの歴史と導入〜
nokomoro3
0
140
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
170
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
1.1k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.1k
A better future with KSS
kneath
239
17k
Typedesign – Prime Four
hannesfritz
42
2.8k
Making Projects Easy
brettharned
117
6.4k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Code Reviewing Like a Champion
maltzj
525
40k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.9k
GitHub's CSS Performance
jonrohan
1032
460k
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