I am trying to wrap my head around Cont and callCC by reducing this function:
s0 = (flip runContT) return $ do (k, n) <- callCC $ \k -> let fx = k (f, x) in return (f, 0) lift $ print n if n < 3 then k (n+1) >> return () else return ()
I managed to achieve this goal:
s21 = runContT (let fx = 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 the moment I have no idea what to do with the recursive definition f What is the best way to complete this reduction?
haskell monads lazy-evaluation continuations tying-the-knot
Ryba
source share