{-# language BlockArguments #-} import Data.Functor.Identity -- 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 = runIdentity do E x1 f1 <- foo n Identity E x2 f2 <- foo (n+1) Identity pure (f1 x1 ++ f2 x2) main :: IO () main = putStrLn (bar' 42)