Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kyo - Functional Scala 2023

Flavio Brasil
November 30, 2023

Kyo - Functional Scala 2023

Kyo is a next-generation effect system that introduces an approach based on algebraic effects to deliver straightforward APIs in the pure Functional Programming paradigm. Unlike similar solutions, Kyo achieves this without inundating developers with esoteric concepts from Category Theory or using cryptic symbolic operators. This results in a development experience that is both intuitive and robust.

Kyo generalizes the innovative effect rotation mechanism introduced by ZIO. While ZIO restricts effects to two channels, namely dependency injection and short-circuiting, Kyo allows for an arbitrary number of effectful channels. This enhancement offers developers greater flexibility in effect management and simplifies Kyo's internal codebase through more principled design patterns.

In addition to this novel approach to effect handling, Kyo provides seamless direct syntax inspired by Monadless and a comprehensive set of built-in effects like Aborts for short-circuiting, Envs for dependency injection, and Fibers for green threads with fine-grained uncooperative preemption.

After over two years in development, the first public release of the project will be made during Functional Scala 2023. Attendees will also be treated to benchmark results that showcase Kyo's unparalleled performance.

Flavio Brasil

November 30, 2023
Tweet

Other Decks in Programming

Transcript

  1. Clump: Batching
 https://github.com/getclump/clump 
 Future: High-perf futures https://github.com/traneio/future Arrows: Monadic

    staging
 https://github.com/traneio/arrows NDBC: Async DB drivers https://github.com/traneio/ndbc
  2. A decade working on large-scale systems • SoundCloud, Twitter, Nubank

    • Delivered major performance optimizations for Finagle, Twitter Future, Stitch, Graal, Clojure • Saw hundreds of crashes Scala — Graal
 ScalaMatsuri 2019 https://youtu.be/a6dK3eXhO7k?si=T775S1sKFu5B4wSf
  3. ZIO[R, E, A] type IO[+E, +A] = ZIO[Any, E, A]

    type Task[+A] = ZIO[Any, Throwable, A] type RIO[-R, +A] = ZIO[R, Throwable, A] type UIO[+A] = ZIO[Any, Nothing, A] type URIO[-R, +A] = ZIO[R, Nothing, A]
  4. ZIO[R, E, A] Do we really need a fixed arity?

    Why assume the computation uses IO and Async? Why only dependency injection and short-circuiting? What if we could express an unbounded number of effects?
  5. type Caches = Envs[Cache] & IOs type Databases = Envs[Database]

    & Aborts[DBException] & IOs A > (Databases & Caches)
  6. type Caches = Envs[Cache] & IOs type Databases = Envs[Database]

    & Aborts[DBException] & Caches A > Databases
  7. opaque type >[+T, -S] = T | Kyo[_, _, _,

    T, S] Original Design Implicit conversions from/to T > Any and T
  8. opaque type >[+T, -S] = T | Kyo[_, _, _,

    T, S] After Scala 2 support
  9. type >[+T, -S] >: T After Scala 2 support Any

    type T is a subclass of T > Any
  10. type >[+T, -S] >: T After Scala 2 support Any

    type T is a subclass of T > Any val a: Int > Any = 1 val b: Int = a.pure
  11. Effect Widening val a: Int > Any = 1 


    val b: Int > Options = a 

  12. Effect Widening val a: Int > Any = 1 


    val b: Int > Options = a 
 
 val c: Int > (Options & Tries) = b 
 

  13. Effect Widening val a: Int > Any = 1 


    val b: Int > Options = a 
 
 val c: Int > (Options & Tries) = b 
 
 val d: Int > (Options & Tries) = 42
  14. def example1(v: Int > (Options & Tries)) = v.map(_ +

    1) def example2(v: Int > Tries) = example1(v) 
 Fluent APIs
  15. Fluent APIs def example1(v: Int > (Options & Tries)) =

    v.map(_ + 1) def example2(v: Int > Tries) = example1(v) 
 
 def example3 = example1(42)
  16. def example( a: Int > Options, b: Int > Tries

    ): Int > (Options & Tries) = a.flatMap(v => b.map(_ + v))
  17. def example( a: Int > Options, b: Int > Tries

    ): Int > (Options & Tries) = a.map(v => b.map(_ + v))
  18. Locals Scoped Values Aspects Aspect-Oriented Programming Options Optional Values Tries

    Exception Handling Consoles Console Interaction Clocks Time Management Randoms Random Values Loggers Logging Stats Observability Queues Concurrent Queuing Channels Backpressured Communication Hubs Broadcasting with Backpressure Meters Computational Limits Timers Scheduled Execution Latches Fiber Coordination Atomics Concurrent State Adders Concurrent Accumulation Caches Memoized Functions via Caffeine
  19. Targets Kyo, Cats-effect, ZIO, Ox Data Throughput, Allocation, Profiling Environment

    Github Large Runner 8 cores, 32 GB Ubuntu 22.04 Source code 
 https://github.com/getkyo/kyo/tree/main/kyo-bench/src/main/scala/kyo/bench https://tinyurl.com/kyo-benchs
  20. Caprese Kyo delivers Caprese’s key promises without language changes, with

    a complete set of effects and next-level performance
  21. Caprese Kyo delivers Caprese’s key promises without language changes, with

    a complete set of effects and next-level performance in Scala 2, 3, and JS
  22. Caprese Kyo delivers Caprese’s key promises without language changes, with

    a complete set of effects and next-level performance in Scala 2, 3, and JS today
  23. CREDITS: This presentation template was created by Slidesgo, and includes

    icons by Flaticon and infographics & images by Freepik Thanks! Any questions? https://getkyo.io https://dev.to/fwbrasil @fbrasisil