[Haskell-cafe] typesafe non-local returns in the IO monad

Simon Peyton-Jones simonpj at microsoft.com
Tue Feb 21 08:07:51 EST 2006


I'm not sure this works. Consider this

	newContinuation (\k -> return (callContinuation k)) ...

The partial application (callContinuation k) has no 's' in its type, and so can go anywhere.

Simon

| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of John
| Meacham
| Sent: 21 February 2006 12:40
| To: haskell-cafe at haskell.org
| Subject: [Haskell-cafe] typesafe non-local returns in the IO monad
| 
| Although I am sure I am not the first to discover this, I thought it was
| a neat application of the runST trick. Safe non-local returns for
| the IO monad. What I mean by safe is that it is impossible to return to
| a context that no longer exists. the api is simple:
| 
| > module System.IO.Continuation(IOCont(),newContinuation,callContinuation) where
| >
| > data IOCont s a = ....
| >
| > newContinuation :: (forall s . IOCont s a -> IO b) -> (a -> IO b) -> IO b
| > newContinuation act cc = ...
| >
| > callContinuation :: IOCont s a -> a -> IO b
| > callContinuation cont x = ...
| 
| newContinuation runs its first argument passing a fresh jumppoint into
| it, if it is jumped to then the argument is passed to the second
| argument of newContinuation.
| 
| the universal quantification means that the continuation is unable to
| escape the action so you know its context is still available on the
| stack.
| 
| in jhc these are just implemented as straight FFI calls to setjmp(2) and
| longjmp(2) and an IORef.
| 
| I feel using the term 'continuation' is something of a misnomer as true
| continuations would allow jumping between multiple stacks I would think
| but am unsure what a good name for this is then. Is there a fully
| typesafe interface for 'true' IO continuations for some definition of
| 'true'? hmm....
| 
|         John
| 
| --
| John Meacham - ⑆repetae.net⑆john⑈
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list