Hello,<br>When I was using C code from Python, the overhead put on calling C code by Python was significant.<br>To simplify, say I have on C-side two procedures f and g, I do all the stuff to call them in a row from Python, well I&#39;m better off factorizing: adding on C side a wrapper h procedure that calls them both, and then call h from Python, because then I will have half as much overhead:<br>

<br>Instead of SwitchToC -&gt; call f -&gt; SwitchToPython -&gt; SwitchToC -&gt; call g -&gt; SwitchToPython,<br>the factorization leads to SwitchToC -&gt; call f -&gt; call g -&gt; SwitchToPython,<br>which gives the same result yet is different performance-wise because each switching has a cost.<br>

<br>This is painful, because if another time I have to call f and j (another function), then I have to make another wrapper.<br><br>In Haskell world, now, given that my functions f and g would have been imported using <b>unsafe</b>:<br>

<br>foreign import unsafe &quot;f&quot; f :: Thing -&gt; Foo -&gt; IO ()<br>foreign import unsafe &quot;g&quot; g :: Stuff -&gt; Bar -&gt; IO ()<br>foreign import unsafe &quot;h&quot; h :: Thing -&gt; Foo -&gt; Stuff -&gt; Bar -&gt; IO ()<br>

<br>Are<br>doStuff = f x y &gt;&gt; g z w<br>and<br>doStuff = h x y z w<br>equivalent, or is there an overhead (e.g. due to IO monad, or due to the way the FFI does the calls) when compiled (if need be with optimizations) with GHC? <br>