to use a function callCC with type MonadCont m => ((a -> m b) -> m a) -> m a. This function has one argument of a function type; that function argument accepts the function too, which discards all computations going after its call. For example, let's break the execution of the pyth function if at least one of its arguments is negative returning zero: pyth_m :: Float -> Float -> Cont a Float pyth_m a b = callCC $ \exitF -> do -- $ sign helps to avoid parentheses: a $ b + c == a (b + c) when (b < 0 || a < 0) (exitF 0.0) -- when :: Applicative f => Bool -> f () -> f () a2 <- pow2_m a b2 <- pow2_m b anb <- cont (add' a2 b2) r <- cont (sqrt' anb) return r Continuations as objects Programming with continuations can also be useful when a caller does not want to wait until the callee completes. For example, in user-interface (UI) programming, a routine can set up dialog box fields and pass these, along with a continuation function, to the UI framework. This call returns right away, allowing the application code to continue while the user interacts with the dialog box. Once the user presses the "OK" button, the framework calls the continuation function with the updated fields. Although this style of coding uses continuations, it is not full CPS. function confirmName() { fields.name = name; framework.Show_dialog_box(fields, confirmNameContinuation); } function confirmNameContinuation(fields) { name = fields.name; } A similar idea can be used when the function must run in a different thread or on a different processor. The framework can execute the called function in a worker thread, then call the continuation function in the original thread with the worker's results. This is in Java 8 using the Swing UI framework: void buttonHandler() { // This is executing in the Swing UI thread. // We can access UI widgets here to get query parameters. int parameter = getField(); new Thread(() => { // This code runs in a separate thread. // We can do things like access a database or a // blocking resource like the network to get data. int result = lookup(parameter); javax.swing.SwingUtilities.invokeLater(() => { // This code runs in the UI thread and can use // the fetched data to fill in UI widgets. setField(result); }); }).start(); }