What Color Is Your Monad
I&#x27;ve been waiting for this piece for a while. Monads don&#x27;t compose!<p>Under an effect-based system:<p><pre><code>    fn get_user&lt;F&gt;() -&gt; F&lt;User&gt; 
</code></pre>
Is like having an explicit effect F:<p><pre><code>    fn get_user&lt;F&gt;() -&gt;{F} User 
</code></pre>
Where {F} is the effect set.<p>Note that User is no longer wrapped in F, and that we can extend the effect set (e.g. {F, G, H})<p>Consider a function that is async and throws an error. Is this:<p><pre><code>    Promise&lt;Exn&lt;T&gt;&gt;
</code></pre>
Or:<p><pre><code>    Exn&lt;Promise&lt;T&gt;&gt;
</code></pre>
Convention (and common sense) dictates the former, but in the face of many effects, who&#x27;s to say there even is an order at all?<p>By using an effect set, we get:<p><pre><code>    {Promise, Exn} T
</code></pre>
And we can even ensure that our function is generic over additional effects:<p><pre><code>    {Promise, Exn, F} T
</code></pre>
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.<p>Cool beans!