{- | Lift MVar operations so you can do them within monads stacked on top of IO. Analogous to MonadIO -}{-# LANGUAGE TupleSections #-}moduleControl.Monad.MVar(MVar,moduleControl.Monad.MVar,liftIO)whereimportControl.Concurrent.MVar(MVar)importqualifiedControl.Concurrent.MVarasIOimportControl.Monad.ErrorimportControl.Monad.ReaderimportControl.Monad.StatenewEmptyMVar::(MonadIOm)=>m(MVara)newEmptyMVar=liftIOIO.newEmptyMVarnewMVar::(MonadIOm)=>a->m(MVara)newMVar=liftIO.IO.newMVartakeMVar::(MonadIOm)=>MVara->matakeMVar=liftIO.IO.takeMVarputMVar::(MonadIOm)=>MVara->a->m()putMVarvar=liftIO.IO.putMVarvarreadMVar::(MonadIOm)=>MVara->mareadMVar=liftIO.IO.readMVarswapMVar::(MonadIOm)=>MVara->a->maswapMVarvar=liftIO.IO.swapMVarvartryTakeMVar::(MonadIOm)=>MVara->m(Maybea)tryTakeMVar=liftIO.IO.tryTakeMVartryPutMVar::(MonadIOm)=>MVara->a->mBooltryPutMVarvar=liftIO.IO.tryPutMVarvarisEmptyMVar::(MonadIOm)=>MVara->mBoolisEmptyMVar=liftIO.IO.isEmptyMVarclass(MonadIOm)=>MonadMVarmwheremodifyMVar::MVara->(a->m(a,b))->mbaddMVarFinalizer::MVara->m()->m()modifyMVar_::(MonadMVarm)=>MVara->(a->ma)->m()modifyMVar_varact=modifyMVarvar$\a->doa'<-actareturn(a',())withMVar::(MonadMVarm)=>MVara->(a->mb)->mbwithMVarvaract=modifyMVarvar$\a->dob<-actareturn(a,b)instanceMonadMVarIOwheremodifyMVar=IO.modifyMVaraddMVarFinalizer=IO.addMVarFinalizerinstance(MonadMVarm,Errore)=>MonadMVar(ErrorTem)wheremodifyMVarvarf=ErrorT$modifyMVarvar$\a->doe<-runErrorT(fa)return$either((a,).Left)(fmapRight)eaddMVarFinalizervar(ErrorTact)=ErrorT$addMVarFinalizervar(act>>return())>>return(Right())-- NOTE, error is silently droppedinstance(MonadMVarm)=>MonadMVar(ReaderTrm)wheremodifyMVarvarf=ReaderT$\r->modifyMVarvar$\a->runReaderT(fa)raddMVarFinalizervar(ReaderTact)=ReaderT(addMVarFinalizervar.act)instance(MonadMVarm)=>MonadMVar(StateTsm)wheremodifyMVarvarf=StateT$\s->modifyMVarvar$\a->do((a',b),s')<-runStateT(fa)sreturn(a',(b,s'))addMVarFinalizervar(StateTact)=StateT$\s->addMVarFinalizervar(acts>>return())>>return((),s)