모든 Monad는 Applicative다. >>= 만으로
(<*>) :: f (a -> b) -> f a -> f b
fs (<*>) xs = fs >>= \fs -> xs >>= \xs -> (fs xs)
모든 Applicative는 Functor다. <*> 만으로
fmap :: (a -> b) -> f a -> f b
fmap fs xs = (pure fs) <*> xs
아래 답변을 보고 "일반화"의 의미에 대해 생각해보면 좋다.
Haskell - is there extended monad type [ m (a -> m b) -> m a -> m b ]
Functor has (a -> b) -> m a -> m b Applicative has f (a -> b) -> f a -> f b Monad has m a -> (a -> m b) -> m b But, Is there extended monad type that has m a -> m (...
stackoverflow.com
'PRGRM > Haskell' 카테고리의 다른 글
[Haskell] Functor, Applicative, Monad의 필요 (0) | 2021.08.18 |
---|