Why does Haskell have no continuations? (http://www.haskell.org/hawiki/CoMonad) If continuations are incompatible with non-strict semantics, I'd appreciate an explanation.
I'm not sure what your question means. You can make your own continuations, so in that sense Haskell has them. But perhaps you're asking why Haskell lacks something like call/cc in Scheme which allows you to grab the current continuation? This doesn't play very well with graph reduction (which most Haskell implementations use), since with graph reduction you will update application nodes with the result of the computation. If you have call/cc available you can "jump back in time" and have a function call return something different, which would contradict the "cached" result from the previous call. It's not an insurmountable problem, but it's pretty hairy. -- Lennart Scott wrote:
Why does Haskell have no continuations? (http://www.haskell.org/hawiki/CoMonad) If continuations are incompatible with non-strict semantics, I'd appreciate an explanation.
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
On Tue, Dec 30, 2003 at 07:21:08AM -0600, Scott wrote:
Why does Haskell have no continuations? (http://www.haskell.org/hawiki/CoMonad)
See http://www.haskell.org/hawiki/MonadCont BTW, the factorial example on http://www.haskell.org/hawiki/MonadicContinuationPassingStyle seems rather pointless to me, because it doesn't use any methods of MonadCont (like callCC). Best regards, Tom -- .signature: Too many levels of symbolic links
G'day all. Quoting Tomasz Zielonka <t.zielonka@students.mimuw.edu.pl>:
BTW, the factorial example on http://www.haskell.org/hawiki/MonadicContinuationPassingStyle seems rather pointless to me, because it doesn't use any methods of MonadCont (like callCC).
The only point of the factorial example is to show how much nicer it looks than the version in ContinuationPassingStyle. Which is useless from the point of view of expressivity, but it does show how CPS and recursion can work together. There are reasons for using CPS as an implementation technique which have nothing to do with call/cc, though this example doesn't really show any of them. Cheers, Andrew Bromage
On Tue, Dec 30, 2003 at 10:31:57PM -0500, ajb@spamcop.net wrote:
G'day all.
Quoting Tomasz Zielonka <t.zielonka@students.mimuw.edu.pl>:
BTW, the factorial example on http://www.haskell.org/hawiki/MonadicContinuationPassingStyle seems rather pointless to me, because it doesn't use any methods of MonadCont (like callCC).
The only point of the factorial example is to show how much nicer it looks than the version in ContinuationPassingStyle. Which is useless from the point of view of expressivity, but it does show how CPS and recursion can work together.
There are reasons for using CPS as an implementation technique which have nothing to do with call/cc, though this example doesn't really show any of them.
OK. I think I may be getting it now. The point is that MonadCont takes care of passing the continuation, so you don't have to do it by hand. Is that right?
Cheers, Andrew Bromage
Best regards, Happy New Year, Tom -- .signature: Too many levels of symbolic links
G'day all. Quoting Tomasz Zielonka <t.zielonka@students.mimuw.edu.pl>:
OK. I think I may be getting it now. The point is that MonadCont takes care of passing the continuation, so you don't have to do it by hand. Is that right?
Precisely.
Happy New Year,
And to you and yours. Cheers, Andrew Bromage
On Tue, 30 Dec 2003, Scott wrote:
Why does Haskell have no continuations? (http://www.haskell.org/hawiki/CoMonad) If continuations are incompatible with non-strict semantics, I'd appreciate an explanation.
With letrec and unrestricted call/cc you can implement ML-style refs: (define (make-cell) ; Alan Bawden, 1989 (call-with-current-continuation (lambda (return-from-make-cell) (letrec ((state (call-with-current-continuation (lambda (return-new-state) (return-from-make-cell (lambda (op) (case op ((set) (lambda (value) (call-with-current-continuation (lambda (return-from-access) (return-new-state (list value return-from-access)))))) ((get) (car state))))))))) ((cadr state) 'done))))) Unrestricted call/cc seems to be incompatible with referential transparency in a very fundamental way, and Haskell is nothing without referential transparency. On the other hand, it doesn't cause any problems when the evaluation order is fixed by some monad, whence MonadCont. In practice, the cool things that call/cc makes possible (backtracking, cooperative multitasking) can be achieved much more easily with custom monads: e.g. the list monad instance Monad [] where m >>= k = concatMap k m return x = [x] fail s = [] versus the amb form in Scheme, which provides essentially the same functionality: (define amb-fail '()) (define (initialize-amb-fail) (set! amb-fail (lambda (x) (error #f "amb tree exhausted")))) ;;for petite chez (define (fail) (amb)) (define-syntax amb (syntax-rules () ((amb argument ...) (let ((old-amb-fail amb-fail)) (call/cc (lambda (return) (call/cc (lambda (next) (set! amb-fail next) (return argument)))... (set! amb-fail old-amb-fail) (amb-fail #f))))))) (initialize-amb-fail) -- Ben
On Tue, 30 Dec 2003 10:38:33 -0800 (PST) Ben Rudiak-Gould <benrg@dark.darkweb.com> wrote:
On Tue, 30 Dec 2003, Scott wrote:
Why does Haskell have no continuations? (http://www.haskell.org/hawiki/CoMonad) If continuations are incompatible with non-strict semantics, I'd appreciate an explanation.
Unrestricted call/cc seems to be incompatible with referential transparency in a very fundamental way, and Haskell is nothing without referential transparency. On the other hand, it doesn't cause any problems when the evaluation order is fixed by some monad, whence MonadCont.
Indeed, the simplest example is probably implementing exceptions with call/cc. Assuming a callCC function what does the following return, callCC (\k -> k 1 + k 2)?
participants (6)
-
ajb@spamcop.net -
Ben Rudiak-Gould -
Derek Elkins -
Lennart Augustsson -
Scott -
Tomasz Zielonka