Menu

I applied Haskell's Applicative Functors to Kotlin Coroutines. Here's what happened.

DEV Community: haskell·Damián Rafael Lattenero·6 months ago
#1DNDZ6Rx
#dev#class#code#strong#highlight
Reading 0:00
15s threshold

How currying, functors, applicative functors and monads from Haskell led me to build a parallel orchestration library for Kotlin coroutines with zero overhead.

tags: kotlin, functionalprogramming, haskell, coroutines

If you know Haskell, you already know this library

In Haskell, combining independent IO actions looks like this:

mkDashboard <$> fetchUser <*> fetchCart <*> fetchPromos

Three independent effects. The runtime can execute them however it wants — including in parallel. The structure tells you: these don't depend on each other.

When one result depends on another, you switch to monadic bind:

do ctx <- mkContext <$> fetchProfile <*> fetchPrefs <*> fetchTier mkDashboard <$> fetchRecs ctx <*> fetchPromos ctx <*> fetchTrending ctx

Phase 1 is applicative (parallel). Phase 2 is monadic (depends on ctx ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.