Skip to content

Instantly share code, notes, and snippets.

@awto
Created November 15, 2012 17:51
Show Gist options
  • Save awto/4080075 to your computer and use it in GitHub Desktop.
Save awto/4080075 to your computer and use it in GitHub Desktop.
shift/reset via double CPS transform
module DoubleCont where
import Control.Monad.Cont
reset :: ContT a (ContT r m) a -> ContT b (ContT r m) a
reset e = ContT $ \k ->
ContT $ \m ->
runContT (runContT e return)
(\r -> runContT (k r) m)
shift :: ((a -> ContT x (ContT r m) x) -> ContT x (ContT r m) x)
-> ContT x (ContT r m) a
shift e = ContT $ \k ->
ContT $ runContT (
runContT (
e (\v -> ContT $ \k' ->
ContT $ \m'' ->
runContT (k v)
(\w -> runContT (k' w) m'')
)
)
return
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment