Thanks, Tobias.<br><br>I guess my eyes kind of glazed over when I read &quot;getElems :: (MArray a e m, Ix i) =&gt; a i e -&gt; m [e]&quot; in the docs, and didn&#39;t relate that to the meaning of &quot;return&quot;... lesson learnt.<div>
<br></div><div>About the extra type info needed -- what part of the type &quot;ST s (STArray s Int Int)&quot; is the compiler unable to infer?</div><div><br></div><div>I&#39;ve worked out from this that the error message &quot;no instance for&quot;... might signal a missing type signature, but I&#39;m having trouble working out the general lesson of when the compiler needs some extra hints.</div>
<div><br></div><div><br>On 25 May 2012 18:50, Matthew Moppett &lt;<a href="mailto:matthewmoppett@gmail.com">matthewmoppett@gmail.com</a>&gt; wrote:<br>&gt; I&#39;ve been trying to use mutable arrays in the ST monad, and wrote out a<br>
&gt; little proof of concept function:<br>&gt;<br>&gt; idST :: [Int] -&gt; [Int]<br>&gt; idST xs = runST $ do<br>&gt;     array &lt;- newListArray (1, (length xs)) xs<br>&gt;     return (getElems array)<br>&gt;<br>&gt; -- where idSt should be equivalent to id.<br>
&gt;<br>&gt; And I get the error message:<br>&gt;<br>&gt; Couldn&#39;t match type `[Int]&#39; with `Int&#39;<br>&gt;     In the return type of a call of `getElems&#39;<br>&gt;     In the first argument of `return&#39;, namely `(getElems array)&#39;<br>
&gt;     In a stmt of a &#39;do&#39; block: return (getElems array)<br>&gt;<br>&gt; Obviously I&#39;m making a very simple mistake here, but I can&#39;t seem to spot<br>&gt; it. Can anyone offer some advice?<br><br>&#39;getElems array&#39; already has type &#39;ST s [Int]&#39;, you don&#39;t need<br>
another &#39;return&#39;. Furthermore you need to help out with the type<br>inference a little bit (it&#39;s similar to the read-show problem).<br>This should work:<br><br>idST :: [Int] -&gt; [Int]<br>idST xs = runST $ do<br>
   array &lt;- newListArray (1, (length xs)) xs :: ST s (STArray s Int Int)<br>   getElems array<br><br>(You could also replace STArray by STUArray.)<br></div>