Can someone comment (or explain) how to do continuation passing style in a strongly typed language like scala?
The curious thing is that if every expression is in tail position, then no function actually returns.
I say "actually" because according to the type inference, the return type is the disjunction of all the types of the
expressions in tail position. However, it seems to me that if a function never returns, the the type of
the expression in tail position is not relevant.
If I must know and declare the return value types of CPS transformed functions, doesn't that make
it impossible to write a CPS compliment program?
Two examples would be a varient of IF which takes a boolean value and two continuations, one
to call if the boolean is true, and the other to call if the boolean is false, or a hash table accessor
which takes a hash table, a perspective key, and two continuations, one 0-ary to call if the key is
not found in the table, and one 1-ary to call with the value if the key is found in the table.
Perhaps this question really doesn't make sense since the JVM prohibits tail-call-optimization between
different global functions.