4 ms·
Who uses CPS in daily programming? Or do you mean using a compiler that uses it?
by sweeneyrod 6y ago
Who uses CPS in daily programming? Or do you mean using a compiler that uses it?
- hintymad 6y agoDefinitely in compiler, but also in daily JavaScript as a way to avoid deeply nested callbacks.
- Twisol 6y agoThe Visitor pattern is not much more than a CPS-style transform that lets you represent sum types in a language without them. A CPS transform for a computation of type `X` gives a computation of type `forall A. (X -> A) -> A`. That is, instead of evaluating to ("returning") a value of type `X`, you take a function that you deliver a valid of type `X` to, and return whatever it returns. CPS-transforming a sum type `X + Y` gives `forall A. (X + Y -> A) -> A`, and if you distribute over the sum you get `forall A. ((X -> A) * (Y -> A)) -> A`. The visitor is the pair of functions you pass in, `(X -> A) * (Y -> A)`, and the value decides which method to call. In either event, it returns whatever the chosen visitor method returns. (Dropping into Java syntax, this is the type of the `visit` method: `<A> A visit(Visitor<A> visitor)` -- and the Visitor is `interface Visitor<A> { A onX(X x); A onY(Y y); }`.)
- skrishnamurthi 6y agoCallback hell in JavaScript.
- emsal 6y agoI'm no expert but I think that the async-await pattern is quite similar to CPS.
- agumonkey 6y agoI cannot claim it is, but async/await, at least in ES seems to be a continuation monad without the do notation.