AnotherEffect(cb =&gt; {
      // do more stuff
    })
  })
})</code></pre><p>This example shows how you can use monads to flatten callbacks without having to use promises:</p><pre><code class="ml"># (* IO as a callback *)
  type 'a io = ('a -&gt; unit) -&gt; unit;;
type 'a io = ('a -&gt; unit) -&gt; unit

# let pure (value: 'a): 'a io = fun cb -&gt; cb value;;
val pure : 'a -&gt; 'a io = &lt;fun&gt;

# let map (f: 'a -&gt; 'b) (x: 'a io): 'b io =
  fun cb -&gt; x (fun value -&gt; cb (f value));;
val map : 