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
1
1.5k
ピュアなドメインを支える技術/pure domain model and the technology behind it
petitviolet
14
10k
小さく始めるクラウドネイティブ/small start CloudNative
petitviolet
0
1.9k
2019年だからこそ12factor app/The Twelve-Factor app in 2019
petitviolet
1
1k
実践GraphQL on Scala/Real world GraphQL on Scala
petitviolet
8
3.1k
Kubernetesを知る/Introduction Kubernertes
petitviolet
1
650
GraphQL on Scala
petitviolet
3
2.7k
Microservices Batch on GAE
petitviolet
0
1.9k
Web API Design
petitviolet
18
8.4k
Other Decks in Programming
See All in Programming
オープンセミナー2025@広島「君はどこで動かすか?」アンケート結果
satoshi256kbyte
0
210
UbieのAIパートナーを支えるコンテキストエンジニアリング実践
syucream
2
730
ECS初心者の仲間 – TUIツール「e1s」の紹介
keidarcy
0
100
RDoc meets YARD
okuramasafumi
2
130
サイトを作ったらNFCタグキーホルダーを爆速で作れ!
yuukis
0
500
AWS Serverless Application Model入門_20250708
smatsuzaki
0
130
GitHub Copilotの全体像と活用のヒント AI駆動開発の最初の一歩
74th
8
3.2k
TanStack DB ~状態管理の新しい考え方~
bmthd
2
340
AIコーディングAgentとの向き合い方
eycjur
0
230
オープンセミナー2025@広島LT技術ブログを続けるには
satoshi256kbyte
0
130
未来を拓くAI技術〜エージェント開発とAI駆動開発〜
leveragestech
2
180
エンジニアのための”最低限いい感じ”デザイン入門
shunshobon
0
130
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
73
5k
The Cult of Friendly URLs
andyhume
79
6.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Music & Morning Musume
bryan
46
6.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
We Have a Design System, Now What?
morganepeng
53
7.7k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
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