{-# LANGUAGE TypeOperators, TypeSynonymInstances, TemplateHaskell #-}moduleData.Record.Label(-- * Lens types.Point(Point),(:->)(Lens),lens,getL,setL,modL,fmapL-- * Bidirectional functor.,(:<->:)(..),Iso(..),lmap,for-- * Monadic lens operations.,getM,setM,modM,(=:),askM,localM-- * Derive labels using Template Haskell.,moduleData.Record.Label.TH)whereimportPreludehiding((.),id)importControl.ApplicativeimportControl.CategoryimportControl.Monad.StateimportControl.Monad.ReaderimportData.Record.Label.THdataPointfio=Point{_get::f->o,_set::i->f->f}_mod::Pointfio->(o->i)->f->f_modlfa=_setl(f(_getla))anewtype(f:->a)=Lens{unLens::Pointfaa}-- | Create a lens out of a getter and setter.lens::(f->a)->(a->f->f)->f:->alensgs=Lens(Pointgs)-- | Get the getter function from a lens.getL::(f:->a)->f->agetL=_get.unLens-- | Get the setter function from a lens.setL::(f:->a)->a->f->fsetL=_set.unLens-- | Get the modifier function from a lens.modL::(f:->a)->(a->a)->f->fmodL=_mod.unLensinstanceCategory(:->)whereid=lensidconstLensa.Lensb=lens(_geta._getb)(_modb._seta)instanceFunctor(Pointfi)wherefmapfx=Point(f._getx)(_setx)instanceApplicative(Pointfi)wherepurea=Point(consta)(constid)a<*>b=Point(_geta<*>_getb)(\r->_setbr._setar)fmapL::Applicativef=>(a:->b)->fa:->fbfmapLl=lens(fmap(getLl))(\xf->setLl<$>x<*>f)-- | This isomorphism type class is like a `Functor' but works in two directions.classIsofwhere(%)::a:<->:b->fa->fb-- | The bijections datatype, a function that works in two directions. infixr7:<->:dataa:<->:b=(:<->:){fw::a->b,bw::b->a}-- | Constructor for bijections.instanceCategory(:<->:)whereid=id:<->:id(a:<->:b).(c:<->:d)=a.c:<->:d.binfixr8%instanceIso((:->)i)wherel%Lensa=lens(fwl._geta)(_seta.bwl)instanceIso((:<->:)i)where(%)=(.)lmap::Functorf=>(a:<->:b)->fa:<->:fblmapl=leta:<->:b=linfmapa:<->:fmapbdimap::(o'->o)->(i->i')->Pointfi'o'->Pointfiodimapfgl=Point(f._getl)(_setl.g)-- | Combine a partial destructor with a lens into something easily used in the-- applicative instance for the hidden `Point' datatype. Internally uses the-- covariant in getter, contravariant in setter bi-functioral-map function.-- (Please refer to the example because this function is just not explainable-- on its own.)for::(i->o)->(f:->o)->Pointfioforab=dimapida(unLensb)-- | Get a value out of state pointed to by the specified lens.getM::MonadStatesm=>s:->b->mbgetM=gets.getL-- | Set a value somewhere in state pointed to by the specified lens.setM::MonadStatesm=>s:->b->b->m()setMl=modify.setLl-- | Alias for `setM' that reads like an assignment.infixr7=:(=:)::MonadStatesm=>s:->b->b->m()(=:)=setM-- | Modify a value with a function somewhere in state pointed to by the-- specified lens.modM::MonadStatesm=>s:->b->(b->b)->m()modMl=modify.modLl-- | Fetch a value pointed to by a lens out of a reader environment.askM::MonadReaderrm=>(r:->b)->mbaskM=asks.getL-- | Execute a computation in a modified environment. The lens is used to-- point out the part to modify.localM::MonadReaderrm=>(r:->b)->(b->b)->ma->malocalMlf=local(modLlf)