class Ref m r | m->r where
newRef
readRef
writeRef
instance Ref IO IORef
writeRef r x = writeIORef r $! x
instance (Ref m r) => Ref (WriterT m) r where
writeRef = lift . writeRef
and so on...
The code snippet above looks like a very good idea. The monad
dependent operations combined with "lift" seem more complicated
than necessary. "lift" in particular often seems like plumbing that
should not be necessary.
Best Wishes,
Greg
Well, lift is the common plumbing that lets you build writeRef and liftIO. So
it is an intermediate invention. In fact it is the only thing in MonadTrans:
class MonadTrans (t::(* -> *) -> * -> *) where
lift :: forall (m::* -> *) a. Monad m => m a -> t m a
-- Imported from Control.Monad.Trans
You are supposed to make higher level shorthand and abstractions from it.
But it helps to learn how the plumbing works.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe