moduleYi.Monad(Ref(..),gets,getsA,getsAndModify,maybeM,modifiesRef,modifiesThenReadsRef,readsRef,repeatUntilM,whenM,with,writesRef)whereimportData.AccessorimportData.IORefimportControl.Monad.ReaderimportControl.Monad.StateimportControl.Monad.TransimportControl.Concurrent.MVar-- | Combination of the Control.Monad.State 'modify' and 'gets'getsAndModify::MonadStatesm=>(s->(s,a))->magetsAndModifyf=doe<-getlet(e',result)=fepute'returnresultclassRefrefwherereadRef::(MonadIOm)=>refa->mawriteRef::(MonadIOm)=>refa->a->m()modifyRef::(MonadIOm)=>refa->(a->a)->m()instanceRefIORefwherereadRefr=liftIO$readIORefrwriteRefrx=liftIO$writeIORefrxmodifyRefrf=liftIO$modifyIORefrfinstanceRefMVarwherereadRefr=liftIO$readMVarrwriteRefrx=liftIO$putMVarrxmodifyRefrf=liftIO$modifyMVar_r(\x->return(fx))modifiesRef::(Refref,MonadReaderrm,MonadIOm)=>(r->refa)->(a->a)->m()modifiesReffg=dob<-asksfmodifyRefbgreadsRef::(Refref,MonadReaderrm,MonadIOm)=>(r->refa)->mareadsReff=dor<-asksfreadRefrwritesRef::(MonadReaderrm,MonadIOm)=>(r->IORefa)->a->m()writesReffx=dor<-asksfwriteRefrxmodifiesThenReadsRef::(MonadReaderrm,MonadIOm)=>(r->IORefa)->(a->a)->mamodifiesThenReadsReffg=domodifiesReffgreadsReffwith::(MonadReaderyim,MonadIOm)=>(yi->component)->(component->IOa)->mawithfg=doyi<-askliftIO$g(fyi)whenM::Monadm=>mBool->m()->m()whenMmtestma=mtest>>=flipwhenmamaybeM::Monadm=>(x->m())->Maybex->m()maybeM_Nothing=return()maybeMf(Justx)=fx-- | Rerun the monad until the boolean result is false, collecting list of results.repeatUntilM::Monadm=>m(Bool,a)->m[a]repeatUntilMm=do(proceed,x)<-mcaseproceedofFalse->return[x]True->doxs<-repeatUntilMmreturn(x:xs)getsA::MonadStatesm=>Accessorsp->(p->a)->magetsAaf=gets(f.getVala)