Abstracting Effects with Continuations to Unify Business Logic
I explore how continuations in Gleam allow us to write a single business logic function that works seamlessly with synchronous, fallible, and asynchronous data sources. Instead of maintaining separate implementations for each scenario, we separate the core logic from the specific effects, letting the caller define how values are fetched and processed.
Using a continuation says: 'I have no idea how you're going to get the value, but when you do, this is what should be done next.'
- Joker_vD
Well, yeah. You can do this, you can take
pub fn simple_func(fetch: fn(String) -> String) -> List(Int) {
let keys = ["a", " b"]
list.map(keys, fn(key) {
let key = string.uppercase(key)
let value = fetch(key)
string.length(value)
})
}
and manually convert it into a code that, instead of performing this computation, builds essentially an AST that could be interpreted to perform this computation. But the whole point of the research into async/await, algebraic effects, etc. is so that you, the programmer, don't have to because your original program is already an AST that could be interpreted to perform the computation!
Your programming language already has semicolons, "foreach", and "return", so why force the programmer to use a combination of "continuation.then()", "continuation.each()", and "continuation.return()" instead? That's very much building a new programming language on top of an existing one and then solving the original problem at hand — well, perhaps the original programming language should just be better at solving the problems you want to solve?
- damienmeur
With the AI era I really think there is a renaissance in functional programming, look at effect-ts which just reached 17M weekly downloads and is recommended by Claude itself when starting a new TypeScript project.
Effect-ts is kind of a continuation DSL interpreter, an interresting concepts they brought in addition to the error channel is the "R" dependency channel so that you can be type guided for missing injected dependencies, very cool for testability.
As all these structures (effects, continuations, ...) are monadic, the best part is the thigh composability possibilities as basically you can jut chain them.
Very cool to live the resurrection of all these 50's mathematics concepts, that takes all their sense now at AI era