Why can't we just call functions directly and let them handle everything?
Image: kees torn, CC BY-SA 2.0, via Wikimedia Commons
Why can't we just call functions directly and let them handle everything?
Imagine you're cooking a meal and need to prepare several dishes at once. You can't just start cooking without knowing when each dish is done and how to serve them.
In cooking, you'd need to keep track of each dish's progress and when to serve them. CPS is like cooking with a recipe that tells you exactly when to finish each dish and serve it, making sure everything comes out perfectly timed.
Example
You have a chicken (C), potatoes (P), and a salad (S). In direct style, you start cooking the chicken and potatoes together. In CPS, you cook the chicken and say, "When you're done, serve the chicken." Then you cook the potatoes and say, "When the potatoes are done, serve them." Finally, you prepare the salad and say, "When the salad is ready, serve it."
Remember this
CPS makes sure each step in a process happens at the right time, like a perfectly timed meal.
Text adapted from Wikipedia, licensed under CC BY-SA 4.0.
Monad (functional programming)
Monads are a type constructor with two operations: return and bind
the Y combinator does: enables recursion in languages without named functions
Can a computer program call itself to solve problems?
parametric polymorphism does: a function works for any type T without knowing what T is
Functions can work with any data type without knowing it!
operator fusion does at the compiler level: merges adjacent ops to reduce memory traffic
Did you know your computer can write faster code than you?
loop unrolling does: trades code size for reduced loop overhead
Can we speed up our computer programs?
Viterbi semiring
How do we find the best path in a maze of choices?
Swipe through 100 ML concepts daily
Open Pocket Polymath