関数Applicative
関数型(->) rのApplicative型クラス
関数Applicativeの定義
code:hs
instance Applicative ((->) r) where
pure x = (\_ -> x)
f <*> g = \x -> f x (g x)
pure :: b -> (a -> b)
constと同じ
Kコンビネータである
(<*>) :: (a -> b -> c) -> (a -> b) -> (a -> c)
Sコンビネータである
Applicative Styleで使う
fmapは(.)と同じである
code:hs
(+) <$> (+3) <*> (*100) $ 5 --508
これが上手くハマるケースがあるのかどうかはわからないmrsekut.icon
関数をFunctor/Applicative/Monadにする - kymmt
関数もアプリカティブ - Qiita