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
初めての関数型プログラミング
Search
petitviolet
September 19, 2015
Programming
1
1.6k
初めての関数型プログラミング
Haskellで始める関数型プログラミング
ざっくりとした紹介とモナド
https://ngineerxiv.doorkeeper.jp/events/29760
petitviolet
September 19, 2015
Tweet
Share
More Decks by petitviolet
See All by petitviolet
Stripeで請求書払い&銀行振込を実装する
petitviolet
0
1.2k
ピュアなドメインを支える技術/pure domain model and the technology behind it
petitviolet
14
9.9k
小さく始めるクラウドネイティブ/small start CloudNative
petitviolet
0
1.8k
2019年だからこそ12factor app/The Twelve-Factor app in 2019
petitviolet
1
970
実践GraphQL on Scala/Real world GraphQL on Scala
petitviolet
8
2.9k
Kubernetesを知る/Introduction Kubernertes
petitviolet
1
620
GraphQL on Scala
petitviolet
3
2.6k
Microservices Batch on GAE
petitviolet
0
1.9k
Web API Design
petitviolet
18
8.2k
Other Decks in Programming
See All in Programming
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
MCP with Cloudflare Workers
yusukebe
2
220
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
180
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
선언형 UI에서의 상태관리
l2hyunwoo
0
140
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
770
CSC509 Lecture 14
javiergs
PRO
0
130
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
Security_for_introducing_eBPF
kentatada
0
110
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Producing Creativity
orderedlist
PRO
341
39k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Six Lessons from altMBA
skipperchong
27
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Transcript
ॳΊͯͷ ؔܕϓϩάϥϛϯά @petitviolet Fringe81 Co., Ltd.
About Me • খࢵ ߂و(Hiroki Komurasaki) • @petitviolet • ৽ଔ1(15ଔ)
• Fringe81͍ͬͯ͏ΞυςΫͷձࣾ • Android/iOSͷࠂSDK։ൃ
ॳΊͯͷ ؔܕϓϩάϥϛϯά
ॳΊͯͷ ؔܕϓϩάϥϛϯά
ॳΊͯͷ Haskell
What is Haskell • ७ਮؔܕϓϩάϥϛϯάݴޠ • ԆධՁ • ੩తܕ͚/ܕਪ •
ͳͲ
७ਮؔܕʁ • ෭࡞༻͕ແ͍ • ࢀরಁաੑ • ಉ͡ೖྗʹରͯ͠ৗʹಉ͡ग़ྗ • ؔୈҰڃ •
jsͷΑ͏ʹؔΛΦϒδΣΫτͱͯ͠ѻ͑Δ
෭࡞༻͕ͳ͍ • ༩͑ΒΕͨҾͷΈΛͬͯ݁ՌΛฦ͢ • ΦϒδΣΫτͷঢ়ଶͱ͔جຊతʹແ͍
ؔʹ͍ͭͯ
໋ྩܗݴޠͷؔ ίϯϐϡʔλʹରͯ͠ ԿΛ͢Δͷ͔Λ͑Δ
ؔܕϓϩάϥϛϯάݴޠͰ ίϯϐϡʔλʹରͯ͠ ԿͰ͋Δͷ͔Λ͑Δ
?
ؔԿͰ͋Δ͔Λ͑Δ • ϑΟϘφονྻ // Python def fib(n): if n <
2: return n return fib(n - 1) + fib(n - 2) [fib(i) for i in range(1, 11)]
ؔԿͰ͋Δ͔Λ͑Δ • ϑΟϘφονྻ // Haskell fib :: [Int] fib =
1 : 1 : zipWith (+) fib (tail fib) take 10 fib 1, 1, 2, 3, 5, 8, 13, … 1, 1, 2, 3, 5, 8, 13, … 1, 1, 2, 3, 5, 8, 13,21…
ԆධՁ • ඞཁͳ͚ͩΛධՁ͢Δͷ͕ԆධՁ • ྻࣗମΛఆٛग़དྷΔ • fibؔແݶͷϑΟϘφονྻΛฦ͢ // Haskell fib
:: [Int] fib = 1 : 1 : zipWith (+) fib (tail fib) fib # ࢮ take 10 fib
ؔ߹ • Unixత • খ͞ͳؔΛΈ߹Θͤͯେ͖ͳͷΛ࡞Δ Prelude> length "hello" 5 Prelude>
show 100 "100" Prelude> (length . show) 100 3
ϥϜμࣜ Prelude> let add = \x y -> x +
y Prelude> foldr add 0 [1..10] 55
\ࢥ͍͖ͬΓΛࡉΊΔͱ ΪϦγϟจࣈͷϥϜμλʹ ݟ͑·͢ΑͶɻ ͍͢͝Haskellֶָ͘͠΅͏ʂ p73
ͳΔ΄Ͳ
ܕʹ͍ͭͯ
੩తܕ͚ && ܕਪ Prelude> let a = 5 + 4
Prelude> :t a a :: Num a => a Prelude> let b :: Num a => a; b = (5 :: Num a => a) + (4 :: Num a => a) Prelude> :t b b :: Num a => a
• ܕͷ࣋ͭੑ࣭Λද͢ΠϯλʔϑΣʔεͬΆ͍ • Numʹଐ͢ܕ””ͱͯ͠ͷੑ࣭Λ࣋ͭ ܕΫϥε Prelude> :t 10 10 ::
Num a => a Prelude> :t 10 :: Int 10 :: Int :: Int Prelude> :t 10 :: Double 10 :: Double :: Double
Ϟφυ
Ϟφυͷલʹཧղ͍ͨͭ͠ • ϑΝϯΫλʔ • ΞϓϦΧςΟϒϑΝϯΫλʔ class Functor f where fmap
:: (a -> b) -> f a -> f b class (Functor f) => Applicative f where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b
• จ຺Λ࣋ͭܭࢉΛ࣮ݱ͢ΔΈ • Maybe͋Δ͔͠Εͳ͍͠ɺͳ͍͔ • Listෳͷ͕͋Δ͔͠Εͳ͍ Ϟφυ Prelude> Just 10
>>= (\x -> Just(x + 4)) Just 14 Prelude> Nothing >>= (\x -> Just(x + 4)) Nothing
• จ຺Λ࣋ͭܭࢉΛ࣮ݱ͢ΔΈ • Maybe͋Δ͔͠Εͳ͍͠ɺͳ͍͔ • Listෳͷ͕͋Δ͔͠Εͳ͍ Ϟφυ Prelude> [1, 2]
>>= (\x -> [10, 20] >>= (\y -> [x, y])) [1,10,1,20,2,10,2,20] Prelude> [1, 2] >>= (\x -> [] >>= (\y -> [x, y])) []
class Monad m where return :: Monad m => a
-> m a (>>=) :: Monad m => m a -> (a -> m b) -> m b … B monad C monad Just 10 >>= (\x -> Just(show x)) = Just “10” B monad SFUVSOB return 10 :: Maybe Int = Just 10 C monad B
• จ຺Λ࣋ͭಉ࢜ͷܭࢉΛ៉ྷʹΔͨΊͷΈ • ϞφυͱɺϞφυΛฦΓͱ͢ΔؔΛ ͍͍ײ͡ʹΈ߹ΘͤͯϞφυΛಘΔ • ܭࢉ݁ՌΛϞφυʹ͢Δ • Just 10
ͱ show ΛͬͯJust “10” • ࣦഊͯͨ͠ΒશମΛࣦഊͤ͞Δ • Nothing Λ show ͠Α͏ͱ͢Δͱ Nothing Ϟφυ
We are hiring! fringe81.com/recruit