tavish pegram
10/21/2021, 5:26 PMraulraja
10/21/2021, 8:59 PMCapabilities
or algebraic effects are nothing more than interface
or fun interface
or any other declaration for that matter that can be declared as one of the context receivers and usually involves suspend funs. https://youtrack.jetbrains.com/issue/KT-10468
@Alejandro Serrano Mena @simon.vergauwen and I had discussed this week some features to complement this multiple receivers and a way to do polymorphism similar to how expect / actual work today in the sense that it has no abstraction runtime cost. Using the arrow-continuation library as foundation and including some of the Effect abstractions we already have for reset / shift in the continuation model we may develop more similar effects that you would be able to use in the same way languages like Unison declare Capabilities.
Currently in Kotlin the missing piece in the context receiver proposal is a means to provide implicit materialization of a with
function that makes all those context concrete, the current solution forces you to nest multiple with
or run
calls over each context before you can invoke a contextual function. With Arrow meta we can reduce that boilerplate nesting for you and potentially resolving implicitly contextual instances you declare as providers.
All algebraic effects are representable in the current continuation model Kotlin has for suspend fun except for multi-shot effects or in general any deterministic effects like List or Streams which instead of DSLs like monad bind they provide push like DSLs yield
or emit
As for categorising those patterns and making a library for Algebraic effects it’s still unexplored. Discussing with Simon and Alejandro effects shown in papers like ambient, flips and others are toy utils. People need FileSystem, Cache and other more powerful abstractions that help with real use case in applications.
TLDR; yes, once context receivers land we can have a pattern for Capabilities
just using interfaces, suspend and multiple context receivers.
If you want to collaborate in this regards feel free to open an issue and list which Capabilities you’d like to have and we can discuss them here or on github and see what comes out of it. 🙂tavish pegram
10/22/2021, 3:11 PMsimon.vergauwen
10/23/2021, 9:34 AMsimon.vergauwen
10/23/2021, 9:34 AMtavish pegram
10/27/2021, 1:54 AMraulraja
10/27/2021, 11:08 AM