Given an applicative functor f
, I had an idea of making a new applicative functor Rev f
like f
but with the order of effects reversed. Here it is:
import Control.Applicative
newtype Rev f a = Rev {unRev :: f a}
instance Functor f => Functor (Rev f) where
fmap f (Rev fx) = Rev (fmap f fx)
instance Applicative f => Applicative (Rev f) where
pure x = Rev (pure x)
(Rev ff) <*> (Rev fx) = Rev (pure (\x f -> f x) <*> fx <*> ff)
My questions are
Applicative
instance (does it obey the Applicative
laws)?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.