Hi,<br><br>I&#39;ve written a circularly linked list, but there is some code in it I feel is redundant, but don&#39;t know how to get rid of:<br><br>-- Transactional loop.&nbsp; A loop is a circular link list.<br>data Loop a<br>
&nbsp;&nbsp; = ItemLink<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { item :: a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , prev :: TVar (Loop a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , next :: TVar (Loop a)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp; | InitLink<br><br>-- Create a new empty transactional loop.<br>newLoop :: a -&gt; STM (TVar (Loop a))<br>
newLoop item = do<br>&nbsp;&nbsp; tLoop &lt;- newTVar InitLink<br>&nbsp;&nbsp; writeTVar tLoop (ItemLink item tLoop tLoop)<br>&nbsp;&nbsp; return tLoop<br><br>In the above, the InitLink value is only ever used in the newLoop function to create a single one element circular linked list.&nbsp; Is there a way to write newLoop to avoid using this value?<br>
<br>Thanks<br><br>-John<br><br>