[Haskell] ANNOUNCE: reference 0.1

Maciej Piechotka uzytkownik2 at gmail.com
Tue Sep 7 14:26:19 EDT 2010


On Tue, 2010-09-07 at 02:15 +0200, Bas van Dijk wrote:
> On Mon, Sep 6, 2010 at 11:55 PM, Maciej Piechotka <uzytkownik2 at gmail.com> wrote:
> > Reference is class which generalizes references and monads they exists
> > in. It means that IORef, STRef and others can be accessed by common
> > interface.
> >
> > Currently it is of form:
> >
> > class Reference r m where
> >
> > 1. There was a proposal to rename the class to MonadRef or
> > MonadReference. IMHO it would imply m -> r functional dependency and
> > therefore disallow the instances for both MVar IO and IORef IO
> >
> > 2. Should the functional dependencies or type famillies be introduced?
> > Personally I don't think so as I would like to allow all of the
> > following:
> >
> >  - IORef IO
> >  - MVar IO
> >  - IORef (ContT IO)
> >  - MVar (ContT IO)
> >
> > Any feedback mostly welcome.
> >
> > Regards
> > PS. Darcs repository will be available soon
> >
> > _______________________________________________
> > Haskell mailing list
> > Haskell at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell
> >
> >
> 


First I'd like to say sorry for error in cafe mailing list address. The
whole e-mail is included above.

> I've played with a somewhat similar idea:
> 
> darcs get http://code.haskell.org/~basvandijk/code/only-read-or-write-vars
> 
> API Docs + Hyperlinked source:
> http://code.haskell.org/~basvandijk/code/only-read-or-write-vars/doc/html/only-read-or-write-vars/
> 
> This is not released (yet) because I'm unsure about the design.
> 
> Especially, I'm unsure whether parameterizing Readable with ¦Á is a good idea:
> 
> class Readable v m ¦Á | v ¢ª m where read  v ¢ª m ¦Á
> 
> and whether parameterizing Writable with ¦Á and ¦Â is a good idea:
> 
> class Writable v ¦Á m ¦Â | v ¢ª m where write  v ¢ª ¦Á ¢ª m ¦Â
> 
> They do allow some some nice instances like:
> 
> instance Readable (TMVar ¦Á) STM (Maybe ¦Á) where
>     read = TMVar.tryTakeTMVar
> 
> instance Writable (TMVar ¦Á) ¦Á STM Bool where
>     write = TMVar.tryPutTMVar
> 
> instance Writable (Chan ¦Á) (End ¦Á) IO () where
>     write t = Chan.unGetChan t  unEnd
> 
> -- | Writing @End x@ to a 'Chan' or 'TChan' writes @x@ to the end of
the channel
> -- instead of to the front. Also see 'unGetChan' and 'unGetTChan'.
> newtype End ¦Á = End {unEnd  ¦Á}
> 
> Regards,
> 
> Bas
> 

I guess they are to some extend like Foldable to FoldableLL and possibly
describing different aspects. Yours seems to be a bit like StateVar[1]
generalized for different monads. Support for ptr & others is additional
bonus.

I wanted clear 1-1 mapping with references - i.e. basic 2 operations
with added third for 'atomic' support. 

For example one of unmentioned law is that:

write r x >> read r  ===  write r x >> return r -- If it's only thread
write r x >> write r y === write r y -- If it's only thread
read r >> read r === read r
read r >>= write r === id -- If it's only thread
read r >>= const f === f -- If it's only thread?

In fact I guess each on them could be used as RULES as IMHO each case in
which it is not necessary true it is undeterministic anyway.

While Chan is clearly writable and readable it cannot be considered a
reference - it do have it purposes but they are usually different then
references.

To sum up - I would not be willing to use Readable/Writable in place of
Reference but I don't say they don't have their purposes.

PS. I took the liberty of continuing sentence.

[1] http://hackage.haskell.org/package/StateVar-1.0.0.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/libraries/attachments/20100907/3559ba03/attachment.bin


More information about the Libraries mailing list