Hi,
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:
-- Transactional loop. A loop is a circular link list.
data Loop a
= ItemLink
{ item :: a
, prev :: TVar (Loop a)
, next :: TVar (Loop a)
}
| InitLink
-- Create a new empty transactional loop.
newLoop :: a -> STM (TVar (Loop a))
newLoop item = do
tLoop <- newTVar InitLink
writeTVar tLoop (ItemLink item tLoop tLoop)
return tLoop
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?
Thanks
-John