鉴于一个应用仿函数f
,我想到了一个新的应用仿函数Rev f
,如f
,但效果的顺序颠倒了。这是:
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)
我的问题是
Applicative
实例(它是否遵守Applicative
法律)?