title: Bind class instance for partially applied functions
body: <p>The definition of the <code>Bind</code> class in the Prelude is:</p>
  
  <pre><code>class Apply m &lt;= Bind m where
    bind :: forall a b. m a -&gt; (a -&gt; m b) -&gt; m b
  </code></pre>
  
  <p>It can be read as a function taking <em>two</em> input parameters, a value in a monadic context (<code>m a</code>) and a function (<code>a -&gt; m b</code>) and returning a value in a monadic context (<code>m b</code>).</p>
  
  <p>The instance of <code>Bind</code> for partially-applied function is defined as:</p>
  
  <pre><code>instance bindFn :: Bind ((-&gt;) r) where
    bind m f x = f (m x) x
  </code></pre>
  
  <p>Which is a function taking <em>three</em> parameters. How does that typecheck?</p>
  
  <p>If I try to replace <code>m a</code> by a more concrete type I get (correct me if I am wrong):</p>
  
  <pre><code>(((-&gt;) ??) a) -&gt; (a -&gt; (((-&gt;) ??) b)) -&gt; (((-&gt;) ??) b)
  </code></pre>
  
  <p>which is equivalent to</p>
  
  <pre><code>(?? -&gt; a) -&gt; (a -&gt; (?? -&gt; b)) -&gt; (?? -&gt; b)
  </code></pre>
  
  <p>Assuming the variable <code>m</code> is bound to <code>(?? -&gt; a</code>), <code>f</code> would get bound to <code>a -&gt; ?? -&gt; b</code>, and <code>x</code> to the second <code>??</code>. </p>
  
  <p>Is my reasoning correct?</p>