title: Types and do notation
body: <p>This is several questions rolled into one:</p>
  
  <ol>
  <li><p>In <code>do</code> notation, does each line have to return the same type? For example, can I write one line in a single <code>do</code> block that returns an <code>IO</code> monad, and another that returns an integer? (My understanding, based on how the de-sugaring with <code>&gt;&gt;</code> and <code>&gt;&gt;=</code> seems to work, is that the answer is no.)</p></li>
  <li><p>If not, then how does the compiler determine what type the lines must all return? In all the examples I've seen, the author takes it as a foregone conclusion that we're just working with <code>IO</code> monads. But how do you know, for a given <code>do</code> block, what each line must return?</p></li>
  <li><p>Again assuming the answer to #1 is no: How do you use functions that don't return the right kind of monad inside a <code>do</code> block? For example, consider this websockets code:</p>
  
  <pre><code>application :: MVar ServerState -&gt; WS.Request -&gt; WS.WebSockets WS.Hybi00 ()
  application state rq = do
    WS.acceptRequest rq
    msg &lt;- WS.receiveData :: WS.WebSockets WS.Hybi00 Text
    return ()
  </code></pre>
  
  <p>Suppose I want to print the value of <code>msg</code>. How would I go about that in a way that doesn't conflict with the type of the <code>do</code> block?</p></li>
  </ol>