title: Monad interface in C++
body: <p>I am currently learning a little bit haskell and started to figure out how monads work.
  Since I normaly code C++ and I think the monad pattern would be (as fas as I understand it right now) be realy awesome to use in C++, too, for example for futures etc,</p>
  
  <p>I wonder if there is a way to implement an interface, or a base class, to enforce a correct overload of the functions <code>bind</code> and <code>return</code> (of cause with another name than return for C++) for derived types?</p>
  
  <p>To make more clear what I am thinking of:</p>
  
  <p>consider we have the following non member function:</p>
  
  <pre><code>auto foo(const int x) const -&gt; std::string;
  </code></pre>
  
  <p>And a member function <code>bar</code> which has different overloads in for different classes:</p>
  
  <pre><code>auto bar() const -&gt; const *Monad&lt;int&gt;;
  </code></pre>
  
  <p>If we now want to do something like this: <code>foo(someMember.bar())</code>,
  this simply doesnt work. So if have to know what bar returns, and for example if it returns a <code>future&lt;int&gt;</code>, we have to call <code>bar().get()</code>, which blocks, even if we dont need to block here.</p>
  
  <p>In haskell we could do something like <code>bar &gt;&gt;= foo</code></p>
  
  <p>So I am asking myself if we could achieve such a behaviour in C++, because when calling <code>foo(x)</code> we dont care if x is a object which boxes an <code>int</code>, and in what kind of class the <code>int</code> is boxed, we just want to apply function <code>foo</code> on the boxed type.</p>
  
  <p>I am sorry I have some problem formulating my thoughts in english, since I am not a native speaker.</p>