Hi,<br><br>I've written a circularly linked list, but there is some code in it I feel is redundant, but don't know how to get rid of:<br><br>-- Transactional loop. A loop is a circular link list.<br>data Loop a<br>
= ItemLink<br> { item :: a<br> , prev :: TVar (Loop a)<br> , next :: TVar (Loop a)<br> }<br> | InitLink<br><br>-- Create a new empty transactional loop.<br>newLoop :: a -> STM (TVar (Loop a))<br>
newLoop item = do<br> tLoop <- newTVar InitLink<br> writeTVar tLoop (ItemLink item tLoop tLoop)<br> 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. Is there a way to write newLoop to avoid using this value?<br>
<br>Thanks<br><br>-John<br><br>