title: How and why does the Haskell Cont monad work?
body: <p>This is how the Cont monad is defined:</p>
  
  <pre><code>newtype Cont r a = Cont { runCont :: (a -&gt; r) -&gt; r }
  
  instance Monad (Cont r) where
      return a = Cont ($ a)
      m &gt;&gt;= k  = Cont $ \c -&gt; runCont m $ \a -&gt; runCont (k a) c
  </code></pre>
  
  <p>Could you explain how and why this works? What is it doing?</p>