Thanks Chris,<br><br>The undefined works for me.<br><br>-John<br><br><div class="gmail_quote">On Wed, Jan 7, 2009 at 11:11 AM, ChrisK <span dir="ltr">&lt;<a href="mailto:haskell@list.mightyreason.com">haskell@list.mightyreason.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">You can use &quot;undefined&quot; or &quot;error ...&quot; :<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
{-# LANGUAGE RecursiveDo #-}<br>
import Control.Concurrent.STM<br>
import Control.Monad.Fix<div class="Ih2E3d"><br>
<br>
-- Transactional loop. &nbsp;A loop is a circular link list.<br>
data Loop a<br>
 &nbsp; = ItemLink<br>
 &nbsp; &nbsp; &nbsp;{ item :: a<br>
 &nbsp; &nbsp; &nbsp;, prev :: TVar (Loop a)<br>
 &nbsp; &nbsp; &nbsp;, next :: TVar (Loop a)<br>
 &nbsp; &nbsp; &nbsp;}<br>
<br></div><div class="Ih2E3d">
-- Create a new empty transactional loop.<br>
newLoop :: a -&gt; STM (TVar (Loop a))<br>
newLoop item = do<br></div>
 &nbsp; tLoop &lt;- newTVar undefined<div class="Ih2E3d"><br>
 &nbsp; writeTVar tLoop (ItemLink item tLoop tLoop)<br>
 &nbsp; return tLoop<br>
</div></blockquote>
<br>
Hmmm.. STM does not have a MonadFix instance. &nbsp;But IO does:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
-- Use MonadFix instance of newLoopIO<br>
newLoopIO :: a -&gt; IO (TVar (Loop a))<br>
newLoopIO item = mfix (\ tLoop -&gt; newTVarIO (ItemLink item tLoop tLoop))<br>
</blockquote>
<br>
But mfix (like fix) is difficult to read in large amounts, so there is &quot;mdo&quot;:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
-- Use RecursiveDo notation<br>
newLoopMDO :: a -&gt; IO (TVar (Loop a))<br>
newLoopMDO item = mdo<br>
 &nbsp; tLoop &lt;- newTVarIO (ItemLink item tLoop tLoop)<br>
 &nbsp; return tLoop<br>
<br>
</blockquote>
<br>
<br>
Cheers,<br>
 &nbsp;Chris<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>