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.5k
初めての関数型プログラミング
Haskellで始める関数型プログラミング
ざっくりとした紹介とモナド
https://ngineerxiv.doorkeeper.jp/events/29760
petitviolet
September 19, 2015
Tweet
Share
More Decks by petitviolet
See All by petitviolet
Stripeで請求書払い&銀行振込を実装する
petitviolet
0
960
ピュアなドメインを支える技術/pure domain model and the technology behind it
petitviolet
14
9.6k
小さく始めるクラウドネイティブ/small start CloudNative
petitviolet
0
1.6k
2019年だからこそ12factor app/The Twelve-Factor app in 2019
petitviolet
1
940
実践GraphQL on Scala/Real world GraphQL on Scala
petitviolet
8
2.8k
Kubernetesを知る/Introduction Kubernertes
petitviolet
1
580
GraphQL on Scala
petitviolet
3
2.5k
Microservices Batch on GAE
petitviolet
0
1.8k
Web API Design
petitviolet
18
7.9k
Other Decks in Programming
See All in Programming
さきがけから振り返るアーキテクチャ刷新 / Reflecting on the Architectural Renewal from the Vanguard
nrslib
2
780
小さな開発会社を作った理由
polidog
0
1.9k
初心者がおさえておきたいAWS CDKのベストプラクティス 2024
konokenj
15
7.3k
Terraformテスト入門
msato
0
540
Composing an API the *right* way (Droidcon Berlin 2024)
zsmb
1
450
AHC035解説
terryu16
0
730
コード生成を伴うLLMエージェント - 2024.07.18 Tokyo AI
smiyawaki0820
11
4.1k
しくじり先生 Image Matching Challenge 2024 編
goosehaaan
0
810
SDCon2024: Enabling DevOps and Team Topologies thru architecture: architecting for fast flow
cer
PRO
0
780
Rustのweb開発を助ける 便利なツール紹介
yuki0418
1
190
Prompt FlowによるLLMアプリケーション開発
yuto2000
1
1k
DynamoDB コスト最適化っぽいことの基本 with Terraform
kuro_kurorrr
2
250
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
23
1.9k
Adopting Sorbet at Scale
ufuk
71
8.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
Fantastic passwords and where to find them - at NoRuKo
philnash
42
2.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
78
15k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Building a Modern Day E-commerce SEO Strategy
aleyda
25
6.7k
Done Done
chrislema
179
15k
Build your cross-platform service in a week with App Engine
jlugia
227
17k
How GitHub Uses GitHub to Build GitHub
holman
471
290k
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