------------------------------------------------------------------------------- |-- Module : Control.Lens.Internal-- Copyright : (C) 2012 Edward Kmett-- License : BSD-style (see the file LICENSE)-- Maintainer : Edward Kmett <ekmett@gmail.com>-- Stability : provisional-- Portability : Rank2Types---- These are some of the explicit Functor instances that leak into the-- type signatures of Control.Lens. You shouldn't need to import this-- module directly, unless you are coming up with a whole new kind of-- \"Family\" and need to add instances.------------------------------------------------------------------------------moduleControl.Lens.Internal(-- * Implementation detailsIndexedStore(..),Focusing(..),Traversed(..),Sequenced(..),AppliedState(..),Min(..),getMin,Max(..),getMax,ElementOf(..),ElementOfResult(..))whereimportControl.ApplicativeimportControl.CategoryimportPreludehiding((.),id)importData.Monoid------------------------------------------------------------------------------- Functors------------------------------------------------------------------------------- | Used by 'Focus'newtypeFocusingmca=Focusing{unfocusing::m(c,a)}instanceMonadm=>Functor(Focusingmc)wherefmapf(Focusingm)=Focusing$do(c,a)<-mreturn(c,fa)instance(Monadm,Monoidc)=>Applicative(Focusingmc)wherepurea=Focusing(return(mempty,a))Focusingmf<*>Focusingma=Focusing$do(c,f)<-mf(d,a)<-mareturn(mappendcd,fa)-- | The indexed store can be used to characterize a 'LensFamily'-- and is used by 'clone'dataIndexedStorecda=IndexedStore(d->a)cinstanceFunctor(IndexedStorecd)wherefmapf(IndexedStoregc)=IndexedStore(f.g)c-- | Applicative composition of @State Int@ with a 'Functor', used-- by 'elementOf', 'elementsOf', 'traverseElement', 'traverseElementsOf'newtypeAppliedStatefa=AppliedState{runAppliedState::Int->(fa,Int)}instanceFunctorf=>Functor(AppliedStatef)wherefmapf(AppliedStatem)=AppliedState$\i->casemiof(fa,j)->(fmapffa,j)instanceApplicativef=>Applicative(AppliedStatef)wherepurea=AppliedState(\i->(purea,i))AppliedStatemf<*>AppliedStatema=AppliedState$\i->casemfiof(ff,j)->casemajof(fa,k)->(ff<*>fa,k)-- | Used internally by 'traverseOf_', 'mapM_' and the like.newtypeTraversedf=Traversed{getTraversed::f()}instanceApplicativef=>Monoid(Traversedf)wheremempty=Traversed(pure())Traversedma`mappend`Traversedmb=Traversed(ma*>mb)-- | Used internally by 'mapM_' and the like.newtypeSequencedm=Sequenced{getSequenced::m()}instanceMonadm=>Monoid(Sequencedm)wheremempty=Sequenced(return())Sequencedma`mappend`Sequencedmb=Sequenced(ma>>mb)-- | Used for 'minimumOf'dataMina=NoMin|MinainstanceOrda=>Monoid(Mina)wheremempty=NoMinmappendNoMinm=mmappendmNoMin=mmappend(Mina)(Minb)=Min(minab)-- | Obtain the minimumgetMin::Mina->MaybeagetMinNoMin=NothinggetMin(Mina)=Justa-- | Used for 'maximumOf'dataMaxa=NoMax|MaxainstanceOrda=>Monoid(Maxa)wheremempty=NoMaxmappendNoMaxm=mmappendmNoMax=mmappend(Maxa)(Maxb)=Max(maxab)-- | Obtain the maximumgetMax::Maxa->MaybeagetMaxNoMax=NothinggetMax(Maxa)=Justa-- | The result of trying to find the nth element of a 'Traversal'.dataElementOfResultfa=Searching{-# UNPACK #-}!Inta|Found{-# UNPACK #-}!Int(fa)|NotFoundStringinstanceFunctorf=>Functor(ElementOfResultf)wherefmapf(Searchingia)=Searchingi(fa)fmapf(Foundias)=Foundi(fmapfas)fmap_(NotFounde)=NotFounde-- | Used to find the nth element of a 'Traversal'.dataElementOffa=ElementOf{getElementOf::Int->ElementOfResultfa}instanceFunctorf=>Functor(ElementOff)wherefmapf(ElementOfm)=ElementOf$\i->casemiofSearchingja->Searchingj(fa)Foundjas->Foundj(fmapfas)NotFounde->NotFoundeinstanceFunctorf=>Applicative(ElementOff)wherepurea=ElementOf$\i->SearchingiaElementOfmf<*>ElementOfma=ElementOf$\i->casemfiofFoundjff->casemajofFound__->NotFound"multiple results"Searchingka->Foundk(fmap($a)ff)NotFounde->NotFoundeSearchingjf->casemajofFoundkas->Foundk(fmapfas)Searchingka->Searchingk(fa)NotFounde->NotFoundeNotFounde->NotFounde