{-# LANGUAGE GADTs #-}{-# LANGUAGE Rank2Types #-}{-# LANGUAGE TypeFamilies #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE FlexibleInstances #-}--------------------------------------------------------------------------------- |-- Module : Control.Lens.Projection-- Copyright : (C) 2012 Edward Kmett-- License : BSD-style (see the file LICENSE)-- Maintainer : Edward Kmett <ekmett@gmail.com>-- Stability : provisional-- Portability : non-portable---------------------------------------------------------------------------------moduleControl.Lens.Projection(Projection,Projective(..),project,by,Project(..),projection,stereo,mirror-- * Simple,SimpleProjection)whereimportControl.ApplicativeimportControl.Lens.TypeimportControl.Lens.GetterimportData.Functor.IdentityimportControl.Lens.Iso-- | A 'Projection' is a 'Traversal' that can also be turned around with 'by' to obtain a 'Getter'typeProjectionabcd=forallkf.(Projectivekad,Applicativef)=>k(c->fd)(a->fa)-- | Used to provide overloading of projections.classProjectivekadwhereprojective::(d->a)->(x->y)->kxyinstanceProjective(->)adwhereprojective_x=x-- | A concrete 'Projection', suitable for storing in a container or extracting an embedding.dataProjectadxy=Project(d->a)(x->y)-- | Compose projections.stereo::Projectivekac=>Projectbcyz->Projectabxy->kxzstereo(Projectgf)(Projectih)=projective(i.g)(f.h)instance(a~a',d~d')=>Projective(Projectad)a'd'whereprojective=Project-- | Reflect a 'Projection'.project::Projectivekad=>Overloaded(Projectad)faacd->Overloadedkfaacdproject(Projectfg)=projectivefg-- | Turn a 'Projection' around to get an embeddingby::Projectad(d->Identityd)(a->Identitya)->Getterdaby(Projectg_)=tog-- | Build a 'Projection'projection::(d->a)->(a->Maybec)->Projectionabcdprojectiondaamc=projectiveda(\cfda->maybe(purea)(fmapda.cfd)(amca))-- | Convert an 'Iso' to a 'Projection'.---- Ideally we would be able to use an 'Iso' directly as a 'Projection', but this opens a can of worms.mirror::Projectivekac=>SimpleIsoac->SimpleProjectionacmirrorl=projection(^.froml)(\a->Just(a^.l))-- | @type 'SimpleProjection' = 'Simple' 'Projection'@typeSimpleProjectionab=Projectionaabb