cps (continuation passing style) in scala

10
CPS CONTINUATION PASSING STYLE WITH SCALA CHENSE Meetup, 4/1/14

Upload: prasanna-kumar

Post on 15-Jan-2015

604 views

Category:

Technology


16 download

DESCRIPTION

Continuation-Passing Style (CPS) in Scala presented at CHENSE meetup held Jan 4 2014.

TRANSCRIPT

Page 1: Cps (continuation passing style) in scala

CPSCONTINUATION PASSING

STYLEWITH SCALA

CHENSE Meetup, 4/1/14

Page 2: Cps (continuation passing style) in scala

ABOUT MEPrasanna Kumar

A Java/Scala programmerfind me @prasseemail me

fork me in githubhttp://github.com/prassee

prassee dot sathian at gmail dotcom

Page 3: Cps (continuation passing style) in scala

WHAT'S COOL ABOUTCONTINUATIONS ?

"Imagine an abstraction which takes youback to a point of failure in a code sothat you can run it again" - Continuations

lets you to do this !!!!

Page 4: Cps (continuation passing style) in scala

CPSCONTINUATIONS-PASSING STYLE

"Continuation-Passing Style(CPS) is a style of programmingin which control is passedexplicitly in the form of a

continuation. It also helps theprogrammers to control theexecution flow of the program

at runtime"CPS is a functional programming techniqueScala has support for "Delimited"ContinuationsDelimited Continuation limits the scope ofContinuation in a certain boundary

Page 5: Cps (continuation passing style) in scala

CPS IN SCALAScala has two keywords for CPS - reset andshiftshift must be contained with-in reset.Since Scala supports 'delimited' CPS thescope of the code for CPS is contained within the reset block

A simple examplereset { shift { k: (Int=>Int) => // The continuation k will be the '_ + 1' below. k(7) } + 1}// Result: 8

Page 6: Cps (continuation passing style) in scala

CPS'ED FILE READING

Page 7: Cps (continuation passing style) in scala

USAGE SCENARIOSException HandlingXXX protocol handler (web frameworks !!!)BacktrackingAPI development

Page 8: Cps (continuation passing style) in scala

QUESTIONS

Page 9: Cps (continuation passing style) in scala

COURTESYHTML 5CSS 3reveal.js

Page 10: Cps (continuation passing style) in scala

THANKS :-)