title: What's going on in this type signature? (Vector.Mutable modifiers in Haskell)
body: <p>Mutable vectors in Haskell have three element-level mutators:</p>
  
  <pre><code>read :: PrimMonad m =&gt; MVector (PrimState m) a -&gt; Int -&gt; m a
  write :: PrimMonad m =&gt; MVector (PrimState m) a -&gt; Int -&gt; a -&gt; m ()
  swap :: PrimMonad m =&gt; MVector (PrimState m) a -&gt; Int -&gt; Int -&gt; m ()
  </code></pre>
  
  <p>Now I can use these fine --</p>
  
  <pre><code>import Data.Vector
  import Data.Vector.Mutable 
  import Control.Monad.ST
  import Control.Monad.Primitive 
  
  incrAt :: Vector Double -&gt; Int -&gt; Vector Double
  incrAt vec i = runST $ do
    mvec &lt;- thaw vec
    oldval &lt;- read mvec i
    write mvec i (oldval + 1)
    freeze mvec
  </code></pre>
  
  <p>But what is going on here?  What is a <code>PrimMonad</code>?  And is <code>PrimState</code> a constructor?</p>
  
  <p>I understand there is some binding going on here, on a <code>PrimMonad</code> class monad. <code>thaw</code> returns <code>m (MVector (PrimState m) a)</code>, where <code>m</code> is a <code>PrimMonad</code>... but the monad contains itself?  Why is <code>m</code> inside the context of another <code>m</code>?</p>
  
  <p>I see that everything is basically binding on this <code>PrimState</code> or <code>PrimMonad</code>, but I don't see how this has to do with mutable/storable vectors.  Is there something special about those typeclasses that allow them to store state?</p>
  
  <p>Thank you for your time!</p>