gabryon99 / kotlin-effects

A Kotlin library implementing algebraic effect handlers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kotlin Effects

A Kotlin library implementing algebraic effect handlers. This library is the result of my thesis did at the Technical University of Munich with the collaboration of JetBrains Research.

The library shows the feasibility of implementing algebraic effect handlers within the Kotlin programming language. Here is a brief list containing library's main points:

  • Effects are defined with classes/objects inhereting from the Effect interface.
  • Effectful computations are invoked within a handle e with h expression, where e is an effectful function and h is an effect handler.
  • The library does not support multishot continuations.
  • The provided handler semantics is the deep one.
  • Effects are performed using the do/perform notation (maybe not the best Kotlin idiomatic choice).
object Read: Effect<String>

@Test
fun `MPretnar - Simple Read Effect`() {
    handle {
        val firstName = perform(Read)
        val lastname = perform(Read)
        println("Full Name: $firstName $lastname")
    } with { effect ->
        when (effect) {
            is Read -> resume("Bob")
            else -> unhandled()
        }
    }
}

Effect handlers are implemented on top of Kotlin's coroutines system, using linear continuations.

About

A Kotlin library implementing algebraic effect handlers.

License:MIT License


Languages

Language:Kotlin 54.8%Language:HTML 21.3%Language:JavaScript 13.9%Language:CSS 10.0%