-- | Lenses allow you to use fields of the state of a state monad as if they were variables in an imperative language.-- 'access' is used to retrieve the value of a variable, and '~=' and '%=' allow you to set and modify a variable.-- C-style compound assignments are also provided.moduleLens.Family.State.Lazy(focus,access,(%=),(~=),(%%=)-- * Compound Assignments,(+=),(-=),(*=),(//=),(&&=),(||=),(<>=)-- * Types,Focusing)whereimportData.Monoid(Monoid,mappend)importControl.Monad(liftM)importControl.Monad.Trans.State.Lazy(StateT(..),get,modify)importLens.Family(Getter,Setter,(^.),(%~))importLens.Family.Stock(Ref)importLens.Family.State.Focus(Focusing(..)){- all these Monad constraints could be weakened to Functor constraints -}-- | Lift a stateful operation on a field to a stateful operation on the whole state.-- This is a good way to call a \"subroutine\" that only needs access to part of the state.focus::Monadm=>Ref(Focusingmc)ab->StateTbmc->StateTamcfocuslm=StateT$unFocusing.l(Focusing.(runStateTm))-- | Retrieve a field of the stateaccess::Monadm=>Getterab->StateTambaccessl=(^.l)`liftM`getinfix4%=-- | Modify a field of the state(%=)::Monadm=>Setterab->(b->b)->StateTam()l%=f=modify(l%~f)infix4~=-- | Set a field of the state(~=)::Monadm=>Setterab->b->StateTam()l~=v=l%=constvinfix4%%=-- | Modify a field of the state while returning another value(%%=)::Monadm=>Ref(Focusingmc)ab->(b->(c,b))->StateTamcl%%=f=focusl(StateT(return.f))infixr4+=,-=,*=(+=),(-=),(*=)::(Monadm,Numb)=>Setterab->b->StateTam()f+=b=f%=(+b)f-=b=f%=subtractbf*=b=f%=(*b)infixr4//=(//=)::(Monadm,Fractionalb)=>Setterab->b->StateTam()f//=b=f%=(/b)infixr4&&=,||=(&&=),(||=)::Monadm=>SetteraBool->Bool->StateTam()f&&=b=f%=(&&b)f||=b=f%=(||b)infixr4<>=(<>=)::(Monoido,Monadm)=>Setterao->o->StateTam()f<>=b=f%=(`mappend`b)