Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: Delimited Continuations Explained - Not

Interested in the concept of continuation, I started reading wikis, posts, and came to this "simple" example:

reset {
  ...
  shift { k: (Int=>Int) =>  // the continuation k will be the '_ + 1' below
    k(7)
  } + 1
}
// result: 8

Without knowledge of Scala, I'm totally lost here, could not figure out how the 8 comes out.

Below is how I tried to figure out the meaning but failed. Any guy could you please give me a short explanation? Yeah there are Scala grammar books but they are too thick, I'm more interested in understanding delimited continuation concept than master Scala language...

  • (Int=>Int)

    Looks like a C# delegate, input is Int, output is Int.

  • k: (Int=>Int) => k(7)

    I'm lost here... what is k, and what is (Int=>Int)=>k(7)?

  • shift { k: (Int=>Int) => k(7) } + 1

    Even more lost...

  • reset { ...; shift { k: (Int=>Int) => k(7) } + 1 }

    Even even more and more lost...

like image 217
athos Avatar asked Sep 02 '25 04:09

athos


1 Answers

I found Chris League's talk, "Monadologie: Professional Help for Type Anxiety" (http://vimeo.com/13304075) contains one of better examples of a delimited continuation.

like image 169
user142435 Avatar answered Sep 05 '25 00:09

user142435