title: Understanding Monad Transformer Type Signatures
body: <p>I'm currently tackling monad transformers and trying to really understand the type signatures, and I'm having some confusion. Let's use the following stack for discussion:</p>
  
  <pre><code>newtype Stack s m a = Stack { runStack :: ReaderT s (StateT s IO) a }
  </code></pre>
  
  <p>I'm trying to go through layer by layer and write the unwrapped type signatures but getting stuck:</p>
  
  <pre><code>newtype Stack s m a = Stack { 
      runStack :: ReaderT s         (StateT s IO)       a }
  --              ReaderT s                  m          a
  --                      s -&gt;               m          a
  --                      s -&gt;         (StateT s IO)    a
  --                            StateT  s     m         a
  --                      s -&gt;         (s -&gt; IO (a, s)) a  
  </code></pre>
  
  <p>That just doesn't look like a valid return type signature on the last line, we have essentially a function that takes an s and returns a function shoved up against an <code>a</code>? </p>
  
  <p>I <em>get</em> that the inner function evaluates to a Monad eventually, and that's why it's the <code>m</code> in <code>ReaderT r m a</code>, but it's bending my brain. </p>
  
  <p>Could anyone offer any insight, have I correceclty analyzed the types and I just have to accept that <code>s -&gt; (s -&gt; IO (a, s)) a</code> is indeed valid?</p>
  
  <p>Thank you</p>