tag:blogger.com,1999:blog-6373963829340632529.post911503994452346448..comments2024-01-30T05:40:30.415-03:00Comments on Algorithmically challenged: Delimited Continuations Explained (in Scala)Danielhttp://www.blogger.com/profile/07505997833685327219noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-6373963829340632529.post-77791827340166566982022-02-10T06:33:13.491-03:002022-02-10T06:33:13.491-03:00This comment has been removed by a blog administrator.메리트카지노https://xn--c79a67g3zy6dt4w.com/noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-64399869949842073472013-01-21T22:37:50.520-02:002013-01-21T22:37:50.520-02:00A previous post is not quite correct, but trying t...A previous post is not quite correct, but trying this:<br /><br />def fib(n: Int): Int @cps[Int] = {<br /> def fib0(n: Int, sub1: Int, sub2: Int): Int @cps[Int] = n match {<br /> case x if (math.abs(x) < 2) => shift { k: (Int=>Int) => k(x) }<br /> case x => fib0(x - sub1, sub1, sub2) + fib0(x - sub2, sub1, sub2)<br /> }<br /> val s = math.signum(n)<br /> fib0(n - s, s, s * 2)<br />}<br /><br />throws java.lang.StackOverflowError:<br /><br />reset { fib(15) }<br /><br />Is it possible to handle this, using continuations? Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-24044565088001036882013-01-21T22:13:08.531-02:002013-01-21T22:13:08.531-02:00Great article! I did it almost instantly
def a(x:...Great article! I did it almost instantly<br /><br />def a(x: Int) = shift { k: (Int=>Int) => k(x) } <br /><br />def fib(n: Int): Int @cps[Int] = n match {<br /> case x if (x > 2) => fib(x - 2) + fib(x - 1)<br /> case x => a(x)<br />}<br /><br />reset {<br /> fib(5)<br />}<br /><br />Now, continue reading... ^) Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-84643783040945221372012-01-16T06:32:50.651-02:002012-01-16T06:32:50.651-02:00Great explanation on continuations.
Thanks !
@Se...Great explanation on continuations.<br /><br />Thanks !<br /><br />@Seth : Thanks ... that paper really helps!Hendyhttps://www.blogger.com/profile/05192845149798446052noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-23281492177797622662011-07-20T21:25:05.549-03:002011-07-20T21:25:05.549-03:00@Eric Kolotyluk: Continuations weren't necessa...@Eric Kolotyluk: Continuations weren't necessarily intended for use at the UI layer..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-68831796915611844102011-06-06T11:34:35.077-03:002011-06-06T11:34:35.077-03:00I agree that "Deprecating the Observer Patter...I agree that "Deprecating the Observer Pattern" is a good article, but that article also ties my brain in knots.<br /><br />I would really like to see a non trivial example of how continuations can work in the UI that I can follow.Eric Kolotylukhttps://www.blogger.com/profile/01769240665191271229noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-44706849329616395452011-06-03T23:27:36.155-03:002011-06-03T23:27:36.155-03:00"Deprecating the Observer Pattern (Maier, Rom..."Deprecating the Observer Pattern (Maier, Rompf, and Oderksy, http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf) is a good article for seeing how continuations can be more than just a way to tie your brain in knots. It shows how you can use continuations to write event-handling code without having to break it up into a bunch of separate event handlers.Seth Tisuehttps://www.blogger.com/profile/18193878850743685199noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-88081955256360159652011-03-25T09:50:21.016-03:002011-03-25T09:50:21.016-03:00I am planning to use continuation support in the s...I am planning to use continuation support in the scala language through shift and reset to track the users who are logged in(We are trying to use this instead of using session or cookie to track the users logged in). So please provide us any sample programe to implement the continuation support through shift and reset to track the logged users in scala.monisahttps://www.blogger.com/profile/05261354165376832223noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-29722884139852128862010-10-25T12:23:59.875-02:002010-10-25T12:23:59.875-02:00You are correct. "Before" should be move...You are correct. "Before" should be moved outside the function call to be strictly correct. I'll consider how to rewrite that explanation.Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-29943205521480095582010-10-25T09:59:34.784-02:002010-10-25T09:59:34.784-02:00the example:
reset {
println(1)
shift { (cont: ...the example:<br /><br />reset {<br /> println(1)<br /> shift { (cont: Unit => Unit) =><br /> cont()<br /> cont()<br /> println(2)<br /> }<br /> println(3)<br />}<br /><br />would not work as expected using your transformation "rule":<br /><br />Reset { before shift { k => ... k(something) ... } after }<br /><br />( k => ... k(something) ... ) {x => { before x after }}<br /><br />i think the example should be "translated" to:<br /><br />println(1); ((c: Unit => Unit) => { c(); c(); println(2) }) ((x: Unit) => println(3))<br /><br />?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-36938573110756274052010-09-25T16:17:26.148-03:002010-09-25T16:17:26.148-03:00An interesting thing you could do with continuatio...An interesting thing you could do with continuations is: stop a process send it over the the network to an other computer and then continue at the point where you left of. There is a Framework that implements this behavior on top of scala using continuations.<br /><br />http://code.google.com/p/swarm-dpl/Unknownhttps://www.blogger.com/profile/15265000290624223788noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-67842067438825889722010-09-22T15:59:00.096-03:002010-09-22T15:59:00.096-03:00I also agree that it is quite mind twisting, and I...I also agree that it is quite mind twisting, and I have been unable to get any of the examples to work in Eclipse with the latest Scala plugin.<br /><br />From what I understand, continuations are another form of control like if, while, try, etc. The motivation is to make it easier to express some forms of control in distributed or parallel applications. Unfortunately I don't understand well enough to give a clear example.Eric Kolotylukhttps://www.blogger.com/profile/01769240665191271229noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-74215530053827490152010-09-22T07:25:42.856-03:002010-09-22T07:25:42.856-03:00Please could you explain what is the motivation of...Please could you explain what is the motivation of continuations ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-50602783283797415332010-09-22T07:15:02.963-03:002010-09-22T07:15:02.963-03:00Is it possible to explain simply what is the motiv...Is it possible to explain simply what is the motivationon this brain twisting non-sense ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-39747647916964960322010-09-17T23:10:09.357-03:002010-09-17T23:10:09.357-03:00"Programming Languages: Application and Inter..."Programming Languages: Application and Interpretation" has some beautiful examples on general continuations, using them for a micro-web-framework. For that purpose, continuations are already used in practice in various cases. A success story about this was written by Paul Graham:<br /><br />http://www.paulgraham.com/avg.html<br />http://lib.store.yahoo.net/lib/paulgraham/bbnexcerpts.txt<br /><br />I would really like, however, to understand how to do the same with delimited continuations. It seems to me (with my current limited understanding) that one needs to use reify to save the continuation, which looks even scarier!Anonymoushttps://www.blogger.com/profile/04485097839438234853noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-36026510548567335212010-09-16T20:29:20.847-03:002010-09-16T20:29:20.847-03:00Oh. Never mind.
How did I do so much research o...Oh. Never mind.<br /><br /><br />How did I do so much research on continuations, call/cc, and continuation passing style in order to wrap my head around it, and miss this?<br /><br />Sorry.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-78424414872895355342010-09-12T18:09:19.759-03:002010-09-12T18:09:19.759-03:00Well, it outputs what you think it shouldn't. ...Well, it outputs what you think it shouldn't. The question is, why do you think it is wrong? Perhaps you read all about general continuations and not enough of delimited continuations? Or was it something in my text that lead you to expect otherwise?Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-74625570510059842152010-09-12T17:30:26.701-03:002010-09-12T17:30:26.701-03:00Wait.
That's WRONG.
A "Continuation&quo...Wait.<br /><br />That's WRONG.<br /><br />A "Continuation", as I understand it, works like this:<br /><br />reset {<br /> val y = shift { (k : Int => Unit)<br /> val x = 2 + 3<br /> println("Inside call/cc")<br /> k( x )<br /> println("This never gets printed.")<br /> }<br /> println("2 + 3 = " + y)<br />}<br /><br />Should output<br /><br />Inside call/cc<br />2 + 3 = 5<br /><br />Not<br /><br />Inside call/cc<br />2 + 3 = 5<br />This never gets printed.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-22466813788793623712010-06-14T17:18:04.533-03:002010-06-14T17:18:04.533-03:00This is by far the best explanation of continuatio...This is by far the best explanation of continuations in Scala I have seen yet. I mostly understand what is going on now, but continuations as part of an expression is still a little mind warping, and seems to have no utility I can think of.<br /><br />It would be interesting to see if continuations could make User Interface implementation a little easier by replacing SwingUtilities.invokeLater() and/or SwingWorker with something more light weight or more readable.Eric Kolotylukhttps://www.blogger.com/profile/01769240665191271229noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-3314087388402124182010-04-23T16:03:23.750-03:002010-04-23T16:03:23.750-03:00It is really not any different from that, in the s...It is really not any different from that, in the same sense that Java is not really any different than machine code.<br /><br />Passing callbacks:<br />((k1: String => List[(String,Int)]) => left.flatMap(k1))<br />((x: String) => ((k2: Int => List[(String,Int)]) => right.flatMap(k2))<br />((y: Int) => List((x,y)))<br />)<br /><br />Using delimited continations:<br />List((left.reflect[Any], right.reflect[Any]))Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-87897733227843985702010-04-23T13:25:33.269-03:002010-04-23T13:25:33.269-03:00Except for the "different" new syntax, h...Except for the "different" new syntax, how is this any better from defining functions that take callback functions as a parameter?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-39321188351743067252009-07-04T10:47:13.846-03:002009-07-04T10:47:13.846-03:00All my links got broken. Blogger's doing, not ...All my links got broken. Blogger's doing, not mine.Danielhttps://www.blogger.com/profile/07505997833685327219noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-2033911583259006162009-07-04T09:33:21.089-03:002009-07-04T09:33:21.089-03:00Well, from What I understood, shift and reset will...Well, from What I understood, shift and reset will be implemented as a library + compiler plugin. I'm still struggling with the "List Monad as continuation" exampleRicardo Limahttps://www.blogger.com/profile/10051265214145371756noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-77045810601592927562009-07-04T06:18:08.522-03:002009-07-04T06:18:08.522-03:00Thanks for a great article. The concept of continu...Thanks for a great article. The concept of continuations is finally beginning to make sense for me.<br /><br />For what areas/problems do you see yourself using continuations?eivindwhttp://tihlde.org/~eivindw/noreply@blogger.comtag:blogger.com,1999:blog-6373963829340632529.post-80680004545520870692009-07-04T05:49:32.892-03:002009-07-04T05:49:32.892-03:00The wiki link is broken.The wiki link is broken.Andreihttps://www.blogger.com/profile/14263952686769006465noreply@blogger.com