Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 22. Delimited Continuations > Transforming Nested Control Contexts

22.10. Transforming Nested Control Contexts

The CPS transformation is more complex when it has to deal with calls to transformed functions. To see this, let us look at turning a recursive visit into an iteration, like in Section 22.7, “Turning a Recursive Visit into an Iteration,” on page 326. For simplicity, we will visit a linked list, not a tree:

def visit(a: List[String]): String @cps[String] = {
  if (a.isEmpty) "" else {
    shift {
      k: (Unit => String) => {
        cont = k
        a.head
      }
    }
    visit(a.tail)
  }
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial