I'm struggling to understand what precisely does it mean when a value has type A @cps[B,C] and what types of this form should I assign to my values when using the delimited continuations facility.
I've looked at some sources:
http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf
http://www.scala-lang.org/node/2096
http://dcsobral.blogs...
Hello,
I have an asynchronous control-flow like the following:
ActorA ! DoA(dataA, callback1, callbackOnErrorA)
def callback1() = {
...
ActorB ! DoB(dataB, callback2, callbackOnErrorB)
}
def callback2() = {
ActorC ! DoC(dataC, callback3, callbackOnErrorC)
}
...
How would I divide this flow into several parts (continuations)...
Scala includes the continuations plugin now (yay), but must be enabled by passing "-P:continuations:enable" to the scala compiler. Is there a way to pass arbitrary arguments to scalac for the eclipse scala plugin?
From: http://permalink.gmane.org/gmane.comp.lang.scala/19439
the plugin is loaded by default, but
it must be enabled ...
The following function generates a 'stack level too deep (SystemStackError)' for n = 5,000
def factorial(n)
n == 0 ? 1 : factorial(n -1) * n
end
Is there a way to avoid this error using continuations/callcc?
Note:
I know this can be implemented without recursion. e.g.
def factorial2(n)
(1..n).inject(1) {|result, n| result * n ...
I try building the following simple Generator using the Scala 2.8 Continuations-PlugIn.
Where does the following error come from?
None/None/Some((Unit,Unit))
GenTest.scala:8: error: found cps expression in non-cps position
yieldValue(1)
None/None/Some((Unit,Unit))
GenTest.scala:9: error: found cps expression in non-cps position...
It's been a few months since I've touched Scheme and decided to implement a command line income partitioner using Scheme.
My initial implementation used plain recursion over the continuation, but I figured a continuation would be more appropriate to this type of program. I would appreciate it if anyone (more skilled with Scheme than I) ...
The state monad "interface"
class MonadState s m where
get :: m s
put :: s -> m ()
(+ return and bind) allows to construct any possible computation with State monad without using State constructor. For example, State $ \s -> (s+1, s-1) can be written as
do s <- get
put (s-1)
return (s+1)
Similarily, I never have to...
Having the following class which is in a CPS-context (@cps[Unit]) how would I implement the Seq-trait?
Do I have to leave the standard traits like Seq aside and just implement map, flatmap and foreach in the cps-context?
class DataFlowVariable[T] {
def apply(): T @cps[Unit] = ...
}
class DataFlowStream[T] extends Seq[T] {
override...
Scala 2.8.0.RC1 includes the continuations plugin on trunk for the first time, but the details of how to get access to the shift and reset operations have changed from previous releases, so it's difficult to follow the blog entries and SO answers out there that talk about continuations but were written for previous versions.
See also ht...
Hi, using the CPS compiler-plugin of Scala 2.8, there are the two magic controls reset and shift. Reset delimits the continuation and shift captures the continuation.
There is an example of using CPS with NIO, using nested resets as a type of "forking"...?
I don't exactly understand the purpose of nesting the resets, what's the effect?
...
Hi All,
I need to understand Continuations in Scheme for my upcoming exams and I have no idea about continuations at all. Can anyone please suggest me sources of how to go about learning continuations?
Regards,
darkie
...
Hello, is there any way to have a tail-recursive function inside CPS not throwing a StackOverflow?
import scala.util.continuations._
object CPSStackOverflow {
def main(args: Array[String]) = {
reset {
def recurse(i: Int): Unit @suspendable = {
println(i)
shift { k: (Unit => Unit) =>
k( () ) // just ...
The Wikipedia article on Continuation says:
"In any language which supports closures, it is possible to write programs in continuation passing style and manually implement call/cc."
Either that is true and I need to know how to do it or it is not true and that statement needs to be corrected.
If this is true, please show me how to implem...
I am having some trouble understanding the behavior of the following
Scheme program:
(define c
(dynamic-wind
(lambda () (display 'IN)(newline))
(lambda () (call/cc (lambda (k)
(display 'X)(newline)
k)))
(lambda () (display 'OUT)(newline))))
As I understand, c will be bound to th...
I'm attempting to work on a microthread message passing library in C# using mono. Since Mono 2.4 or so, apparently continuations (not yield) have been available under 'Mono.Tasklets'. However, these lack any documentation that I can find, and while my general use of them works, I get an occasional (but reproducable) crash that the debu...
I'm trying to use various scala implementations of C#-like yield return (i.e. link text) with "for" -constructions such as:
private def permutations[T](s: Vector[T]) = {
def swap(i: Int, j: Int) {
val tmp = s(i)
s.set(i, s.get(j))
s.set(j, tmp)
}
iterator[Vector[T]] {
def generate(left: Int, right: Int): Unit @cps...
Is it possible to serialize a method containing yield statements (or a class that contains such a method) such that when you rehydrate the class, the internal state of the generated iterator is retained?
...
This is how the Cont monad is defined:
newtype Cont r a = Cont { runCont :: (a -> r) -> r }
instance Monad (Cont r) where
return a = Cont ($ a)
m >>= k = Cont $ \c -> runCont m $ \a -> runCont (k a) c
Is there a tutorial somewhere that picks this mumbo-jumbo apart and explains how and why this works? Not looking for a monad ...
Hello,
I'm playing with some kind of DSL defined by an monadic interface.
Since applying the monad using a bunch of flatMap applications is kind of cumbersome and I find for-comprehension syntactically not that beautiful, I'm trying to implicitely mix monadic and non monadic code using delimited continuations.
It's actually working fi...
Basically I want to convert this:
def data(block: T => Unit)
to a Stream (dataToStream is a hypothetical function that do this conversion):
val dataStream: Stream[T] = dataToStream(data)
I suppose this problem could be resolved by continuations:
// let's assume that we don't know how data is implemented
// we just know that it gen...