Comment

Comment by isaacimagine

I've been waiting for this piece for a while. Monads don't compose!

Under an effect-based system:

    fn get_user<F>() -> F<User> 
Is like having an explicit effect F:

    fn get_user<F>() ->{F} User 
Where {F} is the effect set.

Note that User is no longer wrapped in F, and that we can extend the effect set (e.g. {F, G, H})

Consider a function that is async and throws an error. Is this:

    Promise<Exn<T>>
Or:

    Exn<Promise<T>>
Convention (and common sense) dictates the former, but in the face of many effects, who's to say there even is an order at all?

By using an effect set, we get:

    {Promise, Exn} T
And we can even ensure that our function is generic over additional effects:

    {Promise, Exn, F} T
Individual monads compose, but multiple requires explicit composition. By modeling monadic effects using the free monad (i.e. effect sets), we can circumvent the colored function problem entirely: functions can have different colors, and be generic over any other color it might come in contact with.

Cool beans!

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton