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
830
ピュアなドメインを支える技術/pure domain model and the technology behind it
petitviolet
14
9.5k
小さく始めるクラウドネイティブ/small start CloudNative
petitviolet
0
1.6k
2019年だからこそ12factor app/The Twelve-Factor app in 2019
petitviolet
1
930
実践GraphQL on Scala/Real world GraphQL on Scala
petitviolet
8
2.7k
Kubernetesを知る/Introduction Kubernertes
petitviolet
1
570
GraphQL on Scala
petitviolet
3
2.4k
Microservices Batch on GAE
petitviolet
0
1.8k
Web API Design
petitviolet
18
7.7k
Other Decks in Programming
See All in Programming
“Seeing Like a Programmer”—Resiliency, Limits, and Moral Hazards in Software Engineering (LambdaConf 2024)
chriskrycho
0
430
ペパボOpenTelemetry革命
pyama86
2
1.1k
ts-morphを使ってコードリプレイスとASTへのハードルを下げる!
nyawach
5
330
Productivity is Messing Around and Having Fun
hollycummins
1
180
TypeScriptコードの漸進的改善 / Progressive Improvement of TypeScript Code
medley
1
450
ServerAction で Progressive Enhancement はどこまで頑張れるか? / progressive-enhancement-with-server-action
takefumiyoshii
6
520
GitHub Actionsの痒いところを埋めるサードパーティーランナー
dora1998
2
270
Powerfully Typed TypeScript
euxn23
4
1.7k
Long journey of Ruby standard library RubyKaigi 2024
andpad
2
230
Documentation testsの恩恵 / Documentation testing benefits
ssssota
1
560
HonoのRPCで真の型安全が欲しかった
kosei28
1
150
[RubyKaigi 2024] Ruby Mixology 101: adding shots of PHP, Elixir, and more
palkan
0
130
Featured
See All Featured
Building Applications with DynamoDB
mza
88
5.7k
Making Projects Easy
brettharned
109
5.5k
Optimising Largest Contentful Paint
csswizardry
13
2.4k
Atom: Resistance is Futile
akmur
260
25k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
YesSQL, Process and Tooling at Scale
rocio
165
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
126
32k
Faster Mobile Websites
deanohume
300
30k
Building a Modern Day E-commerce SEO Strategy
aleyda
22
6.5k
Testing 201, or: Great Expectations
jmmastey
30
6.4k
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