Hi all,<br>I have a tuple inside a TVar : <br><font size="1"><span style="font-family: courier new,monospace;">&gt; type MySTM = TVar (Int,Int)</span></font><br><br>Whenever I want to edit/read &#39;a&#39; or &#39;b&#39; I find myself writing :<br>
<font size="1"><span style="font-family: courier new,monospace;">&gt; editFunction mySTM = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(a&#39;,b&#39;) &lt;- readTVar mySTM</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">dostuff a&#39; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">...</span></font><br><br>This is boilerplate stuff, so I decided to write some accessors. So far I have :<br>
<font size="1"><span style="font-family: courier new,monospace;">&gt; getA , getB :: MySTM -&gt; STM Int</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; getA mySTM = do </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt; (a&#39;,b&#39;) &lt;- readTVar mySTM</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; return a&#39;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; getB mySTM = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt; (a&#39;,b&#39;) &lt;- readTVar mySTM</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; return b&#39;</span></font><br>
<br>I want to be able to use these accessors like so:<br><font size="1"><span style="font-family: courier new,monospace;">&gt; doSomethingWithA mySTM = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; case (getA mySTM) of </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt;    1 -&gt; doStuff</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt;    0 -&gt; doSomethingElse</span></font><br>
<br>But getA returns an STM Int, so I still have to do a :<br><font size="1"><span style="font-family: courier new,monospace;">&gt; doSomethingWithA = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt; a&#39; &lt;- (getA mySTM</span>)<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt; case a&#39; of </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&gt;    1 -&gt; doStuff</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&gt;    0 -&gt; doSomethingElse</span></font><br><br>This doesn&#39;t really save me a lot of boilerplate. What is the best way of writing a function that just returns my values do I can work with them in the STM monad without unpacking them all the time?<br>
<br>Thanks ,<br>Deech<br><br><br>