Why not to define it for any monad, for example STM (TVars) and whatever?<br><br><div class="gmail_quote">2010/9/7 Maciej Piechotka <span dir="ltr">&lt;<a href="mailto:uzytkownik2@gmail.com">uzytkownik2@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">On Tue, 2010-09-07 at 02:15 +0200, Bas van Dijk wrote:<br>
&gt; On Mon, Sep 6, 2010 at 11:55 PM, Maciej Piechotka &lt;<a href="mailto:uzytkownik2@gmail.com">uzytkownik2@gmail.com</a>&gt; wrote:<br>
&gt; &gt; Reference is class which generalizes references and monads they exists<br>
&gt; &gt; in. It means that IORef, STRef and others can be accessed by common<br>
&gt; &gt; interface.<br>
&gt; &gt;<br>
&gt; &gt; Currently it is of form:<br>
&gt; &gt;<br>
&gt; &gt; class Reference r m where<br>
&gt; &gt;<br>
&gt; &gt; 1. There was a proposal to rename the class to MonadRef or<br>
&gt; &gt; MonadReference. IMHO it would imply m -&gt; r functional dependency and<br>
&gt; &gt; therefore disallow the instances for both MVar IO and IORef IO<br>
&gt; &gt;<br>
&gt; &gt; 2. Should the functional dependencies or type famillies be introduced?<br>
&gt; &gt; Personally I don&#39;t think so as I would like to allow all of the<br>
&gt; &gt; following:<br>
&gt; &gt;<br>
&gt; &gt;  - IORef IO<br>
&gt; &gt;  - MVar IO<br>
&gt; &gt;  - IORef (ContT IO)<br>
&gt; &gt;  - MVar (ContT IO)<br>
&gt; &gt;<br>
&gt; &gt; Any feedback mostly welcome.<br>
&gt; &gt;<br>
&gt; &gt; Regards<br>
&gt; &gt; PS. Darcs repository will be available soon<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Haskell mailing list<br>
&gt; &gt; <a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br>
&gt; &gt; <a href="http://www.haskell.org/mailman/listinfo/haskell" target="_blank">http://www.haskell.org/mailman/listinfo/haskell</a><br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
<br>
<br>
</div>First I&#39;d like to say sorry for error in cafe mailing list address. The<br>
whole e-mail is included above.<br>
<div class="im"><br>
&gt; I&#39;ve played with a somewhat similar idea:<br>
&gt;<br>
&gt; darcs get <a href="http://code.haskell.org/~basvandijk/code/only-read-or-write-vars" target="_blank">http://code.haskell.org/~basvandijk/code/only-read-or-write-vars</a><br>
&gt;<br>
&gt; API Docs + Hyperlinked source:<br>
&gt; <a href="http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/doc/html/only-read-or-write-vars/" target="_blank">http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/doc/html/only-read-or-write-vars/</a><br>


&gt;<br>
&gt; This is not released (yet) because I&#39;m unsure about the design.<br>
&gt;<br>
&gt; Especially, I&#39;m unsure whether parameterizing Readable with α is a good idea:<br>
&gt;<br>
&gt; class Readable v m α | v → m where read  v → m α<br>
&gt;<br>
&gt; and whether parameterizing Writable with α and β is a good idea:<br>
&gt;<br>
&gt; class Writable v α m β | v → m where write  v → α → m β<br>
&gt;<br>
</div>&gt; They do allow some some nice instances like:<br>
<div class="im">&gt;<br>
&gt; instance Readable (TMVar α) STM (Maybe α) where<br>
&gt;     read = TMVar.tryTakeTMVar<br>
&gt;<br>
&gt; instance Writable (TMVar α) α STM Bool where<br>
&gt;     write = TMVar.tryPutTMVar<br>
&gt;<br>
&gt; instance Writable (Chan α) (End α) IO () where<br>
&gt;     write t = Chan.unGetChan t  unEnd<br>
&gt;<br>
&gt; -- | Writing @End x@ to a &#39;Chan&#39; or &#39;TChan&#39; writes @x@ to the end of<br>
the channel<br>
&gt; -- instead of to the front. Also see &#39;unGetChan&#39; and &#39;unGetTChan&#39;.<br>
&gt; newtype End α = End {unEnd  α}<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt; Bas<br>
&gt;<br>
<br>
</div>I guess they are to some extend like Foldable to FoldableLL and possibly<br>
describing different aspects. Yours seems to be a bit like StateVar[1]<br>
generalized for different monads. Support for ptr &amp; others is additional<br>
bonus.<br>
<br>
I wanted clear 1-1 mapping with references - i.e. basic 2 operations<br>
with added third for &#39;atomic&#39; support.<br>
<br>
For example one of unmentioned law is that:<br>
<br>
write r x &gt;&gt; read r  ===  write r x &gt;&gt; return r -- If it&#39;s only thread<br>
write r x &gt;&gt; write r y === write r y -- If it&#39;s only thread<br>
read r &gt;&gt; read r === read r<br>
read r &gt;&gt;= write r === id -- If it&#39;s only thread<br>
read r &gt;&gt;= const f === f -- If it&#39;s only thread?<br>
<br>
In fact I guess each on them could be used as RULES as IMHO each case in<br>
which it is not necessary true it is undeterministic anyway.<br>
<br>
While Chan is clearly writable and readable it cannot be considered a<br>
reference - it do have it purposes but they are usually different then<br>
references.<br>
<br>
To sum up - I would not be willing to use Readable/Writable in place of<br>
Reference but I don&#39;t say they don&#39;t have their purposes.<br>
<br>
PS. I took the liberty of continuing sentence.<br>
<br>
[1] <a href="http://hackage.haskell.org/package/StateVar-1.0.0.0" target="_blank">http://hackage.haskell.org/package/StateVar-1.0.0.0</a><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>
<br></blockquote></div><br>