[Haskell-cafe] style question: Writer monad or unsafeIOToST?
haskell at list.mightyreason.com
Thu Aug 24 19:28:50 EDT 2006
>> class Ref m r | m->r where
>> 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,
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.
More information about the Haskell-Cafe