SlideShare a Scribd company logo
1 of 9
Download to read offline
アプリカティブファンクター
と
Haskell 2014版
株式会社インフィニットループ
Yanez Sanchez Luis David
2014/06/20 OpenIL vol.2
「Haskell書く?」 「Maybe(  ͡°  ͜ʖ  ͡°)」
● Maybeタイプ
● Just x (Just 1, Just “Haskell”...)
● Nothing (Nothing, Nothing, Nothing....)
● 3 + 2 = 5
● 3 + Just 2 = \(^o^)/オワタ
Functorの説明
● class Functor f where
fmap :: (a -> b) -> f a -> f b
● instance Functor Maybe where
fmap f (Just x) = Just (f x)
fmap f Nothing = Nothing
● Just (3+2)
● fmap (+3) (Just 2)
Applicativeの説明
● class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: f a -> f b -> f b
● instance Applicative Maybe where
pure = Just
Nothing <*> _ = Nothing
(Just f) <*> something = fmap f something
● Just (+3) <*> Just 2
Monadの説明
● class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
● instance Monad Maybe where
return x = Just x
(>>=) Nothing f = Nothing
(>>=) (Just x) f = f x
● Just 1000 >>= half >>= half >>= half >>= half....
half x = if even x
then Just (x `div` 2)
else Nothing
あれ?
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(*>) :: f a -> f b -> f b
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
(>>) :: m a -> m b -> m b
return :: a -> m a
※画像引用元
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
圏論とHaskellの違い
現在のHaskell
Functor
Applicative
Monad
圏論
Haskell 2014版
class Applicative m => Monad m where
-- Minimal complete definition: (>>=) or join
(>>=) :: m a -> (a -> m b) -> m b
m >>= f = join (fmap f m)
(>>) :: m a -> m b -> m b
(>>) = (*>)
join :: m (m a) -> m a
join m = m >>= id
return :: a -> m a
return = pure
fail :: String -> m a
fail s = error s
ご清聴ありがとうございました

More Related Content

What's hot

เมธอด ชั้น ม 6 ห้อง 2
เมธอด ชั้น ม  6 ห้อง 2เมธอด ชั้น ม  6 ห้อง 2
เมธอด ชั้น ม 6 ห้อง 2
Pookie Pook
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
Hiroki Mizuno
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
stasimus
 
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐานภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
Noppanon YourJust'one
 

What's hot (17)

เมธอด ชั้น ม 6 ห้อง 2
เมธอด ชั้น ม  6 ห้อง 2เมธอด ชั้น ม  6 ห้อง 2
เมธอด ชั้น ม 6 ห้อง 2
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
29 inverse functions x
29 inverse functions  x29 inverse functions  x
29 inverse functions x
 
Resoluçãohaskell2
Resoluçãohaskell2Resoluçãohaskell2
Resoluçãohaskell2
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
 
삼성 바다 앱개발 실패 노하우 2부
삼성 바다 앱개발 실패 노하우 2부삼성 바다 앱개발 실패 노하우 2부
삼성 바다 앱개발 실패 노하우 2부
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐานภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
ภาษา C โปรแกรมย่อยและฟังก์ชันมาตรฐาน
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Excelマクロはじめの一歩
Excelマクロはじめの一歩Excelマクロはじめの一歩
Excelマクロはじめの一歩
 
The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31
 
Stack queue
Stack queueStack queue
Stack queue
 

Viewers also liked

大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
infinite_loop
 
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in LinuxSelf Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
inaz2
 
「シュキーン」のコード品質を支えるSonarQube
「シュキーン」のコード品質を支えるSonarQube「シュキーン」のコード品質を支えるSonarQube
「シュキーン」のコード品質を支えるSonarQube
infinite_loop
 
MySQL INDEX+EXPLAIN入門
MySQL INDEX+EXPLAIN入門MySQL INDEX+EXPLAIN入門
MySQL INDEX+EXPLAIN入門
infinite_loop
 

Viewers also liked (20)

利益はデータベースの中にあった!
利益はデータベースの中にあった!利益はデータベースの中にあった!
利益はデータベースの中にあった!
 
Unity上でMMDを動かしてみた
Unity上でMMDを動かしてみたUnity上でMMDを動かしてみた
Unity上でMMDを動かしてみた
 
コンピュータフォレンジックにちょっとだけ触れてみる
コンピュータフォレンジックにちょっとだけ触れてみるコンピュータフォレンジックにちょっとだけ触れてみる
コンピュータフォレンジックにちょっとだけ触れてみる
 
新入社員のための大規模ゲーム開発入門 サーバサイド編
新入社員のための大規模ゲーム開発入門 サーバサイド編新入社員のための大規模ゲーム開発入門 サーバサイド編
新入社員のための大規模ゲーム開発入門 サーバサイド編
 
Dbtechshowcasesapporo mysql-turing-for-cloud-0.9.3
Dbtechshowcasesapporo mysql-turing-for-cloud-0.9.3Dbtechshowcasesapporo mysql-turing-for-cloud-0.9.3
Dbtechshowcasesapporo mysql-turing-for-cloud-0.9.3
 
大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
大規模負荷テストの負荷かけ手法とトラブルシュート 〜JMeterとうまく付き合う方法〜
 
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in LinuxSelf Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
Self Introduction & The Story that I Tried to Make Sayonara ROP Chain in Linux
 
PHPカンファレンス北海道2012 LT資料(PHP検定)
PHPカンファレンス北海道2012 LT資料(PHP検定)PHPカンファレンス北海道2012 LT資料(PHP検定)
PHPカンファレンス北海道2012 LT資料(PHP検定)
 
うそ発見器(うそ
うそ発見器(うそうそ発見器(うそ
うそ発見器(うそ
 
とりあえずこれだけ知っていればお仕事ができる(であろう)gitガチ入門
とりあえずこれだけ知っていればお仕事ができる(であろう)gitガチ入門とりあえずこれだけ知っていればお仕事ができる(であろう)gitガチ入門
とりあえずこれだけ知っていればお仕事ができる(であろう)gitガチ入門
 
Codeceptionことはじめ
CodeceptionことはじめCodeceptionことはじめ
Codeceptionことはじめ
 
株式会社インフィニットループ紹介資料
株式会社インフィニットループ紹介資料株式会社インフィニットループ紹介資料
株式会社インフィニットループ紹介資料
 
IL、VR始めるってよ
IL、VR始めるってよIL、VR始めるってよ
IL、VR始めるってよ
 
Codeceptionの受け入れテストをマネる
Codeceptionの受け入れテストをマネるCodeceptionの受け入れテストをマネる
Codeceptionの受け入れテストをマネる
 
「シュキーン」のコード品質を支えるSonarQube
「シュキーン」のコード品質を支えるSonarQube「シュキーン」のコード品質を支えるSonarQube
「シュキーン」のコード品質を支えるSonarQube
 
1時間でざっくり教えるサーバ運営超入門
1時間でざっくり教えるサーバ運営超入門1時間でざっくり教えるサーバ運営超入門
1時間でざっくり教えるサーバ運営超入門
 
ソーシャルゲームを支える技術 ~ クラウドを活用した高負荷対策
ソーシャルゲームを支える技術 ~ クラウドを活用した高負荷対策ソーシャルゲームを支える技術 ~ クラウドを活用した高負荷対策
ソーシャルゲームを支える技術 ~ クラウドを活用した高負荷対策
 
MySQL INDEX+EXPLAIN入門
MySQL INDEX+EXPLAIN入門MySQL INDEX+EXPLAIN入門
MySQL INDEX+EXPLAIN入門
 
CIの見える化でここまで効率が変わった ~Raspberry Piを使ったLEDソリューション製作記~
CIの見える化でここまで効率が変わった ~Raspberry Piを使ったLEDソリューション製作記~CIの見える化でここまで効率が変わった ~Raspberry Piを使ったLEDソリューション製作記~
CIの見える化でここまで効率が変わった ~Raspberry Piを使ったLEDソリューション製作記~
 
3D勉強会 第1回 3Dプログラミングのススメ
3D勉強会 第1回 3Dプログラミングのススメ3D勉強会 第1回 3Dプログラミングのススメ
3D勉強会 第1回 3Dプログラミングのススメ
 

Similar to アプリカティブファンクターとHaskell 2014版

Functions and graphs
Functions and graphsFunctions and graphs
Functions and graphs
Sujata Tapare
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
indu thakur
 
Polynomial functions
Polynomial functionsPolynomial functions
Polynomial functions
dedearfandy
 

Similar to アプリカティブファンクターとHaskell 2014版 (20)

Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
10. haskell Modules
10. haskell Modules10. haskell Modules
10. haskell Modules
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Functions and graphs
Functions and graphsFunctions and graphs
Functions and graphs
 
Functions
FunctionsFunctions
Functions
 
3. Functions II.pdf
3. Functions II.pdf3. Functions II.pdf
3. Functions II.pdf
 
.
..
.
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
chap 2 Ex#1.1
chap 2 Ex#1.1chap 2 Ex#1.1
chap 2 Ex#1.1
 
Comonads in Haskell
Comonads in HaskellComonads in Haskell
Comonads in Haskell
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Applicative functors by Łukasz Marchewka
Applicative functors by Łukasz MarchewkaApplicative functors by Łukasz Marchewka
Applicative functors by Łukasz Marchewka
 
Calculus- Basics
Calculus- BasicsCalculus- Basics
Calculus- Basics
 
Application of derivatives
Application of derivativesApplication of derivatives
Application of derivatives
 
Polynomial functions
Polynomial functionsPolynomial functions
Polynomial functions
 
Function in Mathematics
Function in MathematicsFunction in Mathematics
Function in Mathematics
 
Applied Calculus: Continuity and Discontinuity of Function
Applied Calculus: Continuity and Discontinuity of FunctionApplied Calculus: Continuity and Discontinuity of Function
Applied Calculus: Continuity and Discontinuity of Function
 
Comp inverse
Comp inverseComp inverse
Comp inverse
 

More from infinite_loop

More from infinite_loop (20)

ChatGPT触ってみた
ChatGPT触ってみたChatGPT触ってみた
ChatGPT触ってみた
 
社内ソフトスキルを考える
社内ソフトスキルを考える社内ソフトスキルを考える
社内ソフトスキルを考える
 
3Dプリンタって いいね
3Dプリンタって いいね3Dプリンタって いいね
3Dプリンタって いいね
 
VRChatでお酒が注げる飲み物アセットの紹介
VRChatでお酒が注げる飲み物アセットの紹介VRChatでお酒が注げる飲み物アセットの紹介
VRChatでお酒が注げる飲み物アセットの紹介
 
アニメーションとスキニングをBurstで独自実装する.pdf
アニメーションとスキニングをBurstで独自実装する.pdfアニメーションとスキニングをBurstで独自実装する.pdf
アニメーションとスキニングをBurstで独自実装する.pdf
 
I ❤ Virtual Machines 仮想環境をより便利に使うツールたち
I ❤ Virtual Machines 仮想環境をより便利に使うツールたちI ❤ Virtual Machines 仮想環境をより便利に使うツールたち
I ❤ Virtual Machines 仮想環境をより便利に使うツールたち
 
500万行のPHPプロジェクトにおけるログ出力の歩み
500万行のPHPプロジェクトにおけるログ出力の歩み500万行のPHPプロジェクトにおけるログ出力の歩み
500万行のPHPプロジェクトにおけるログ出力の歩み
 
ADRという考えを取り入れてみて
ADRという考えを取り入れてみてADRという考えを取り入れてみて
ADRという考えを取り入れてみて
 
リファクタリングで実装が○○分短縮した話
リファクタリングで実装が○○分短縮した話リファクタリングで実装が○○分短縮した話
リファクタリングで実装が○○分短縮した話
 
ゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せますゲームのインフラをAwsで実戦tips全て見せます
ゲームのインフラをAwsで実戦tips全て見せます
 
楽しいVR空間を作る技術と支える技術 #osc19do
楽しいVR空間を作る技術と支える技術 #osc19do楽しいVR空間を作る技術と支える技術 #osc19do
楽しいVR空間を作る技術と支える技術 #osc19do
 
Start rl with_unity_machine_learning_agents
Start rl with_unity_machine_learning_agentsStart rl with_unity_machine_learning_agents
Start rl with_unity_machine_learning_agents
 
UniRx の1歩目
UniRx の1歩目UniRx の1歩目
UniRx の1歩目
 
がんばれ PHP Fiber
がんばれ PHP Fiberがんばれ PHP Fiber
がんばれ PHP Fiber
 
心に残った名前ランキング
心に残った名前ランキング心に残った名前ランキング
心に残った名前ランキング
 
プログラムと名前にまつわる座談会
プログラムと名前にまつわる座談会プログラムと名前にまつわる座談会
プログラムと名前にまつわる座談会
 
名は体を表していますか
名は体を表していますか名は体を表していますか
名は体を表していますか
 
名前の力
名前の力名前の力
名前の力
 
大切な名前[Intro]公開版
大切な名前[Intro]公開版大切な名前[Intro]公開版
大切な名前[Intro]公開版
 
JupyterNotebookとMySQLでゼロからはじめるデータサイエンス
JupyterNotebookとMySQLでゼロからはじめるデータサイエンスJupyterNotebookとMySQLでゼロからはじめるデータサイエンス
JupyterNotebookとMySQLでゼロからはじめるデータサイエンス
 

Recently uploaded

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

アプリカティブファンクターとHaskell 2014版