I’m struggling to understand what precisely does it mean when a value has type A @cpsParam[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.blogspot.com/2009/07/delimited-continuations-explained-in.html
http://blog.richdougherty.com/2009/02/delimited-continuations-in-scala_24.html
but they didn’t give me much intuition into this. In the last link, the author tries to give an explicit explanation, but it is not clear enough anyway.
The A here represents the output of the computation, which is also the input to its continuation. The B represents the return type of that continuation, and the C represents its “final” return type—because shift can do further processing to the returned value and change its type.
I don’t understand the difference between “output of the computation”, “return type of the continuation” and “final return type of the continuation”. They sound like synonyms.
So, people helped me with this one elsewhere. Here is the answer:
So,
shiftis a hole of typeAin a computation{...}of typeB. The argument ofshiftreturns a value of typeCand that’s whyreset ({...})has typeC.The key trick in understanding this stuff was to see that
{...}andreset {...}have different type depending on what type theshift‘s argument returns.For example:
returns
List("number 1", "number 2", "number 3").Here
AisInt,BisString,CisList[String]because{"number" + _}is (here) a function fromInttoStringand the argument ofshift, given that function, produces aList[String], which becomes result of thereset({...}).