Skip to content

Instantly share code, notes, and snippets.

@ymdryo
Created February 8, 2024 07:56
Show Gist options
  • Save ymdryo/52d9c4d15f3665ea3a92f44c53902a55 to your computer and use it in GitHub Desktop.
Save ymdryo/52d9c4d15f3665ea3a92f44c53902a55 to your computer and use it in GitHub Desktop.
callCC :: forall r m a. (Shift r <<: m, Monad m) => ((a -> m r) -> m a) -> m a
callCC f = shift @r \k -> k =<< f (k >=> exit)
exit :: (Shift r <<: m, Applicative m) => r -> m a
exit r = shift \_ -> pure r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment