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.8k
小さく始めるクラウドネイティブ/small start CloudNative
petitviolet
0
1.7k
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
610
GraphQL on Scala
petitviolet
3
2.6k
Microservices Batch on GAE
petitviolet
0
1.9k
Web API Design
petitviolet
18
8.1k
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
C++でシェーダを書く
fadis
6
4.1k
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Ethereum_.pdf
nekomatu
0
460
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
イベント駆動で成長して委員会
happymana
1
320
CSC509 Lecture 09
javiergs
PRO
0
140
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Why Our Code Smells
bkeepers
PRO
334
57k
Side Projects
sachag
452
42k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Ruby is Unlike a Banana
tanoku
97
11k
Producing Creativity
orderedlist
PRO
341
39k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Thoughts on Productivity
jonyablonski
67
4.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