I am wondering if there is Applicativeone that can track how many application operations have occurred. I tried to implement it as follows:
import Control.Applicative
main :: IO ()
main = print $ run 1 $ (,,,) <$> FromInt id <*> FromInt id <*> FromInt id <*> FromInt id
data FromInt a = FromInt (Int -> a)
run :: Int -> FromInt a -> a
run i (FromInt f) = f i
instance Functor FromInt where
fmap g (FromInt f) = FromInt (g . f)
instance Applicative FromInt where
pure a = FromInt (const a)
FromInt f <*> FromInt g = FromInt (\i -> f i (g (i + 1)))
But this, of course, does not work. If we call runhaskell in the file, we get the following:
(1,2,2,2)
And I want this:
(1,2,3,4)
, , ( , yesod- ). - State, , ( , mhelper). , , . .