Your SlideShare is downloading. ×
アプリカティブファンクターとHaskell 2014版
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

958
views

Published on

2014年6月20日に開催された勉強会 OpenIL Vol2内で使用されたスライド資料。

2014年6月20日に開催された勉強会 OpenIL Vol2内で使用されたスライド資料。

Published in: Technology, Education

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
958
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
1
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. アプリカティブファンクター と Haskell 2014版 株式会社インフィニットループ Yanez Sanchez Luis David 2014/06/20 OpenIL vol.2
  • 2. 「Haskell書く?」 「Maybe( ͡° ͜ʖ ͡°)」 ● Maybeタイプ ● Just x (Just 1, Just “Haskell”...) ● Nothing (Nothing, Nothing, Nothing....) ● 3 + 2 = 5 ● 3 + Just 2 = \(^o^)/オワタ
  • 3. 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)
  • 4. 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
  • 5. 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
  • 6. あれ? 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
  • 7. 圏論とHaskellの違い 現在のHaskell Functor Applicative Monad 圏論
  • 8. 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
  • 9. ご清聴ありがとうございました

×