Hi, I'm experimenting with delimited continuations in the effort to understand how they work and when it's convenient to use them.
Consider this piece of code (install the CC-delcont before running it): ---- {-# LANGUAGE NoMonomorphismRestriction #-} import Control.Monad.CC import Control.Monad.Trans -- why do I have to import this? data Monad m => Susp m a b = Stop | Susp (a -> m (Susp m a b)) job = reset $ \p -> let askMsg = shift p $ \k -> return $ Susp $ k . return in do x <- askMsg liftIO $ putStrLn $ "x was " ++ show x y <- askMsg liftIO $ putStrLn $ "y was " ++ show y return Stop scheduler j = do Susp nj <- j Susp nj <- nj "Hello!" nj "World!" return undefined main = runCCT $ scheduler job ---- which produces the output: ---- [pa...@bagend haskell]$ runhaskell dc.hs x was "Hello!" y was "World!" [pa...@bagend haskell]$ ---- The goal of this is to have a test-case implementation of the system call mechanism found in operating systems, like the one described by Oleg in (see page 3): http://okmij.org/ftp/papers/context-OS.pdf In effect, this is a bit different from the syscall service routine described by Oleg, as the scheduler function reacts in different ways for subsequent calls (the first time feeds "Hello!", the second one "World!", in a nice monad style). Yet, I liked the separation between the scheduler and the job, which are two completely different values and which I tried to keep. As this is (almost) my first time using delconts, could you provide feedback, comments, opinions about my piece of code and the topic in general (convenience, performances, alternatives and so on)? Thank you, Cristiano _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe