[Haskell-cafe] Re: Re: [Haskell] ANNOUNCE: reference 0.1

Maciej Piechotka uzytkownik2 at gmail.com
Wed Sep 8 04:19:03 EDT 2010

On Wed, 2010-09-08 at 09:53 +0200, Alberto G. Corona wrote:
> Ah, ok. I though that your intention was to restrict the class
> definition for the IO monad . Goood.
> Maybe in the long term, it make sense to include this type class in
> some  monad related package such is mtl, since  references are part of
> many user monads. I think also that some default instances can be
> defined for transformed monads.

Yes - they can. 

In fact:

instance (MonadTrans t, Monad (t m),
          Reference r m) => Reference r (t m) where
    newRef = lift . newRef
    readRef = lift . readRef
    writeRef r = lift . writeRef r

instance (MonadIO m, Reference r IO) => Reference r m where
    newRef = liftIO . newRef
    readRef = liftIO . readRef
    writeRef r = liftIO . writeRef r

> It is pleasant for me to read and write something like
> x <- readRef rx
> rather than
> x<- readMyMonadRef sx
> Such generalizatiopns may be also good for extracting more common
> patterns among different monads. 

Actually the primary need was to create mutable single-linked list for
iteratee-parsec. I didn't wanted to restrict myself to ST or IO so I
choose to add class for them.

-------------- 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/20100908/b667394c/attachment.bin

More information about the Libraries mailing list