newtype Cont k a = Cont { runCont :: (a -> k) -> k }
instance Functor (Cont k) where
-- fmap :: (a -> b) -> (Cont k a) -> (Cont k b)
fmap f (Cont akTok) = Cont $ ???
My doubts:
We can only write Functor instance to any data type that can produce a type out (ex: [a], Maybe a, (y -> a)), but not for the data types that consumes a type. Now in the above data type it consumes a function that consumes a then how does this indirect consumption's can be considered as producing a type a. That means we cannot write Functor instance for (k -> a) -> k?
How can I read the Cont data type. Cont produces k when it have a? (Just like Javascript XHR callback produces JSON when it have response from fetching data from server?)
How to write QuickCheck test cases for Cont data type
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
newtype Cont k a = Cont { runCont :: (a -> k) -> k }
instance Functor (Cont k) where
...
instance Applicative (Cont k) where
...
instance Monad (Cont k) where
...
instance (Arbitrary a, Arbitrary b) => Arbitrary (Cont k a) where
arbitrary = do
-- akTok <- arbitrary -- How to generate Arbitrary functions like this
return $ Cont akTok
instance (Eq k, Eq a) => EqProp (Cont k a) where
(=-=) = eq -- How can I test this equality
main :: IO ()
main = do
let trigger :: Cont ???
trigger = undefined
quickBatch $ functor trigger
quickBatch $ applicative trigger
quickBatch $ monad trigger