I'm trying to wrap my head around Cont and callCC, by reducing this function:
s0 = (flip runContT) return $ do
(k, n) <- callCC $ \k -> let f x = k (f, x)
in return (f, 0)
lift $ print n
if n < 3
then k (n+1) >> return ()
else return ()
I've managed to reach this point:
s21 = runContT (let f x = ContT $ \_ -> cc (f, x) in ContT ($(f,0))) cc where
cc = (\(k,n) -> let
iff = if n < 3 then k (n+1) else ContT ($())
in print n >> runContT iff (\_ -> return ()))
And at this point i have no idea what to do with recursive definition of f
What is the best way to finish this reduction?
You can proceed as follows.