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.
Regards
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell
