title: Object Expression as Computation Builder
body: <p>Given a generic interface declaration like</p>
  
  <pre><code>type IFoo&lt;'T,'MT&gt; =
      abstract Return : 'T -&gt; 'MT
      abstract Bind : 'MT * ('T -&gt; 'MT) -&gt; 'MT
  </code></pre>
  
  <p>it's actually possible to use object expressions as computation builder expressions, which could provide for an interesting approach to the division between encapsulation and execution logic of monadic workflows.</p>
  
  <pre><code>let inline addOption mx my = 
      {   new IFoo&lt;_,_&gt; with
          member __.Return x = Some x
          member __.Bind(ma, f) = Option.bind f ma }
          {   let! x = mx
              let! y = my
              return x + y }
  // val inline addOption :
  //   mx: ^a option -&gt; my: ^a option -&gt;  ^a option
  //     when  ^a : (static member ( + ) :  ^a *  ^a -&gt;  ^a)
  
  addOption (Some 1) (Some 2)
  // val it : int option = Some 3
  addOption None (Some 2)
  // val it : int option = None
  </code></pre>
  
  <p>The compiler checks on the type of the expression if the expected methods are present. But it is only halfway there; because for real monads, I would need to get the method signature <code>abstract Bind : 'MT * ('T -&gt; 'MU) -&gt; 'MU</code> honoured, a projection to a different non-encapsulated type. Why can't this be done?</p>