{-# language BlockArguments #-} import Control.Monad.Cont -- This is the worst of both worlds for LOL. Don't do this. :) data E = forall a. E a (a -> String) foo :: Int -> (E -> r) -> r foo n k | even n = k (E (show n) id) | otherwise = k (E n show) bar' :: Int -> String bar' n = flip runCont id do E x1 f1 <- cont (foo n) E x2 f2 <- cont (foo (n+1)) pure (f1 x1 ++ f2 x2) main :: IO () main = putStrLn (bar' 42)