úÎÖiÏym      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklRankNTypes, TemplateHaskell provisionalEdward Kmett <ekmett@gmail.com>NonePThis class allows us to use . on a number of different monad transformers. KUse a lens to lift an operation with simpler context into a larger context Every  can be used as a  or a  or m&, so it can transitively be used as a  n or   as well. : type MultiLens a b = MultiLensFamily a a b b A  can be used directly as a   or a n and provides m the ability to both read and update multiple fields, subject to the (relatively weak) MultiLensFamily laws. A  can be used directly as a o or as a m, and hence it can be as a MutliGetterFamily. 0In general while your combinators may produce a  it is better to consume any o. 2 type Getter a b = GetterFamily a a b b Every  can be used directly as a  . 7 type Setter a b = SetterFamily a a b b A  c describes a way to perform polymorphic update to potentially multiple fields in a way that can be C composed with other lens-like constructions that can be used as a  . The typical way to obtain a   is to build one with 1 or to compose some other lens-like construction  with a  . *Note: the only lens law that applies to a   is  - writing l c (writing l b a) = writing l c a since  a SetterFamily doesn'4t work, so the other two laws can never be invoked. UA LensFamily is a more general form of a Lens that permits polymorphic field updates 3With great power comes great responsibility, and a   is subject to the lens laws:  ! reading l (writing l b a) = b ! writing l (reading l a) a = a - writing l c (writing l b a) = writing l c a uThese laws are strong enough that the 4 type parameters of a LensFamily cannot vary fully independently. For more on  how they interact, read the Why is it a Lens Family? section of  /http://comonad.com/reader/2012/mirrored-lenses/. Every   can be used as a o, a   or a %, which transitively means it can be  used as a n. ADespite the complicated signature the pattern for implementing a   is the same as a Lens. ! in fact the implementation doesn'1t change, the type signature merely generalizes. $ sndL :: LensFamily (c,a) (c,b) a b  sndL f (a,c) = (,) a <$> f c €A Lens is a purely functional reference to part of a data structure, it can be used to read or write to that part of the whole. 3With great power comes great responsibility, and a   is subject to the lens laws:  ! reading l (writing l b a) = b ! writing l (reading l a) a = a - writing l c (writing l b a) = writing l c a Every   can be used directly as a   or as a , , or ,, which transitively mens it can be used as  almost anything! Such as a , a o, a n, a m, or a  . 0 type Lens a b = LensFamily a a b b Build a   or   from a getter and a setter J lens :: Functor f => (a -> c) -> (d -> a -> b) -> (c -> f d) -> a -> f b Built a   or  . from an isomorphism or an isomorphism family D iso :: Functor f => (a -> c) -> (d -> b) -> (c -> f d) -> a -> f b Build a Getter or GetterFamily ,Building a MultiGetter or MultiGetterFamily Build a Setter or SetterFamily Get the value of a ,   or   or the fold of a  m,  or  that points at monoidal  values. Modify the target of a  ,   or all the targets of a   Multilens, ,  or   Modify the target of a  ,   or all the targets of a   Multilens, ,  or   Replace the target of a  ,  ,  or   Read the value of a ,   or  .  This is the same operation as . Read a field from a ,   or  . I The fixity and semantics are such that subsequent field accesses can be : performed with (Prelude..) This is the same operation as ' flip reading' 5 ghci> ((0, 1 :+ 2), 3)^.fstL.sndL.getting magnitude  2.23606797749979 Modifies the target of a  ,  , , or  . This is an infix version of  Replaces the target(s) of a  ,  ,  or  . This is an infix version of  0Increment the target(s) of a numerically valued   or Setter'  ghci> fstL ^+= 1 $ (1,2)  (2,2) 0Decrement the target(s) of a numerically valued   or   ghci> fstL ^-= 2 $ (1,2)  (-1,2) /Multiply the target(s) of a numerically valued   or Setter'  ghci> sndL ^*= 4 $ (1,2)  (1,8) -Divide the target(s) of a numerically valued   or   Logically p the target(s) of a q-valued   or   Logically r the target(s) of a q-valued   or   Cloning a   or  ) is one way to make sure you arent given  something weaker, such as a  or , and can be used ? as a way to pass around lenses that have to be monomorphic in f. QThis is a lens family that can change the value (and type) of the first field of  a pair. !As  &, but for the second field of a pair. "=This lens can be used to read, write or delete a member of a s. 3 ghci> Map.fromList [("hello",12)] ^. keyL "hello"  Just 12 #>This lens can be used to read, write or delete a member of an t.  0 ghci> IntMap.fromList [(1,"hello")] ^. keyL 1  Just "hello" ; ghci> keyL 2 ^= "goodbye" $ IntMap.fromList [(1,"hello")] & fromList [(1,"hello"),(2,"goodbye")] $=This lens can be used to read, write or delete a member of a u 3 ghci> memberL 3 ^= False $ Set.fromList [1,2,3,4]  fromList [1,2,4] %>This lens can be used to read, write or delete a member of an v 9 ghci> intMemberL 3 ^= False $ IntSet.fromList [1,2,3,4]  fromList [1,2,4] &CThis lens can be used to access the contents of the Identity monad 'HThis lens can be used to change the result of a function but only where $ the arguments match the key given. ( Access a field of a state monad ).Set the value of a field in our monadic state *1Modify the value of a field in our monadic state +VModify the value of a field in our monadic state and return some information about it ,<Modify a numeric field in our monadic state by adding to it -CModify a numeric field in our monadic state by subtracting from it .>Modify a numeric field in our monadic state by multiplying it /;Modify a numeric field in our monadic state by dividing it 0EModify a boolean field in our monadic state by computing its logical r with another value. 1EModify a boolean field in our monadic state by computing its logical p with another value. 2 J foldMapOf :: Monoid m => MultiGetterFamily a b c d -> (c -> m) -> a -> m 3 ; foldOf :: Monoid m => MultiGetterFamily a b m d -> a -> m 4 F foldrOf :: MultiGetterFamily a b c d -> (c -> e -> e) -> e -> a -> e 5 3 toListOf :: MultiGetterFamily a b c d -> a -> [c] 6 4 andOf :: MultiGetterFamily a b Bool d -> a -> Bool 7 3 orOf :: MultiGetterFamily a b Bool d -> a -> Bool 8 @ anyOf :: MultiGetterFamily a b c d -> (c -> Bool) -> a -> Bool 9 @ allOf :: MultiGetterFamily a b c d -> (c -> Bool) -> a -> Bool : < productOf :: Num c => MultiGetterFamily a b c d -> a -> c ; 8 sumOf :: Num c => MultiGetterFamily a b c d -> a -> c < V traverseOf_ :: Applicative f => MultiGetterFamily a b c d -> (c -> f e) -> a -> f () = Q forOf_ :: Applicative f => MultiGetterFamily a b c d -> a -> (c -> f e) -> f () > N sequenceAOf_ :: Applicative f => MultiGetterFamily a b (f ()) d -> a -> f () ? L mapMOf_ :: Monad m => MultiGetterFamily a b c d -> (c -> m e) -> a -> m () @ L forMOf_ :: Monad m => MultiGetterFamily a b c d -> a -> (c -> m e) -> m () A F sequenceOf_ :: Monad m => MultiGetterFamily a b (m b) d -> a -> m () B1The sum of a collection of actions, generalizing G. B asumOf :: Alternative f => MultiGetterFamily a b c d -> a -> f c C1The sum of a collection of actions, generalizing G. @ msumOf :: MonadPlus m => MultiGetterFamily a b c d -> a -> m c D ? elemOf :: Eq c => MultiGetterFamily a b c d -> c -> a -> Bool E B notElemOf :: Eq c => MultiGetterFamily a b c d -> c -> a -> Bool F D concatMapOf :: MultiGetterFamily a b c d -> (c -> [e]) -> a -> [e] METhis is the partial lens that never succeeds at returning any values 4 constML :: Applicative f => (c -> f d) -> a -> f a N 7 headML :: Applicative f => (a -> f a) -> [a] -> f [a] O ; tailML :: Applicative f => ([a] -> f [a]) -> [a] -> f [a] P;A multilens for tweaking the left-hand value in an Either: G leftML :: Applicative f => (a -> f b) -> Either a c -> f (Either b c) Q<A multilens for tweaking the right-hand value in an Either:  H rightML :: Applicative f => (a -> f b) -> Either c a -> f (Either c a)  rightML = traverse Unfortunately the instance for 'Traversable (Either c)' is still missing from  base. R N keyML :: (Applicative f, Ord k) => k -> (v -> f v) -> Map k v -> f (Map k v)  keyML k = keyL k . traverse S L intKeyML :: Applicative f => Int -> (v -> f v) -> IntMap v -> f (IntMap v) # intKeyML k = intKeyL k . traverse T T elementML :: (Applicative f, Traversable t) => Int -> (a -> f a) -> t a -> f (t a) U4Derive lenses with the provided name transformation ! and filtering function. Produce  Just lensName to generate a lens  of the resultant name, or Nothing to not generate a lens  for the input record name. Example usage: , makeLensesBy (\n -> Just (n ++ "L")) ''Foo V*Derive lenses for the record selectors in ( a single-constructor data declaration, 6 or for the record selector in a newtype declaration. 7 Lenses will only be generated for record fields which " are prefixed with an underscore. Example usage:  makeLenses ''Foo W/Derive lenses, specifying explicit pairings of (fieldName, lensName). Example usage: < makeLensesFor [("_foo", "fooLens"), ("bar", "lbar")] ''Foo w'We can focus Reader environments, too! a  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUthe name transformer VWxyzw{|}~X  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX  VUW (*)+,-./10 !"#$%&'L24358967:;<=>?@ABCFGDEMRSNOPQTHIJK`  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWxyzw{|}~ RankNTypes provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedXGSometimes you need to store a path lens into a container, but at least F at this time, impredicative polymorphism in GHC is somewhat lacking. FThis type provides a way to, say, store a list of polymorphic lenses. [Representable Functors. A € f is [ if it is isomorphic to (x -> a) > for some x. All such functors can be represented by choosing x to be ? the set of lenses that are polymorphic in the contents of the €,  that is to say  x = Rep f is a valid choice of x for every  [ €. @Note: Some sources refer to covariant representable functors as ) corepresentable functors, and leave the " representable" name to 1 contravariant functors (those are isomorphic to (a -> x) for some x). LAs the covariant case is vastly more common, and both are often referred to = as representable functors, we choose to call these functors [  here. ]The representation of a [ € as Lenses ^^# is a valid default definition for  for a representable  functor.  $ fmapRep f m = rep $ \i -> f (m^.i) "Usage for a representable functor Foo:  instance Functor Foo where  fmap = fmapRep __# is a valid default definition for ‚ and ƒ for a  representable functor.   pureRep = rep . const "Usage for a representable functor Foo:   instance Applicative Foo where  pure = pureRep  (<*>) = apRep  instance Monad Foo where  return = pureRep  (>>=) = bindRep ``# is a valid default definition for '( *)' for a representable  functor.  ) apRep mf ma = rep $ \i -> mf^.i $ ma^.i "Usage for a representable functor Foo:  instance Applicative Foo where  pure = pureRep  (<*>) = apRep aa+ is a valid default default definition for '(>>=)' for a  representable functor.  & bindRep m f = rep $ \i -> f(m^.i)^.i "Usage for a representable functor Foo:  instance Monad ... where  return = pureRep  (>>=) = bindRep bA default definition for  for a [ €  . distributeRep wf = rep $ \i -> fmap (^.i) wf Typical Usage: ! instance Distributive ... where  distribute = distributeRep cA [ €. has a fixed shape. This fills each position  in it with a X d Map over a [ €" with access to the lens for the  current position ) mapWithKey f m = rep $ \i -> f i (m^.i) e Traverse a [ €! with access to the current path f Traverse a [ €! with access to the current path " as a lens, discarding the result g Traverse a [ €! with access to the current path ( and a lens (and the arguments flipped) h„ over a [ €! with access to the current path  as a lens i„ over a [ €! with access to the current path " as a lens, discarding the result j„ over a [ €! with access to the current path ( as a lens (with the arguments flipped) k Fold over a [ €! with access to the current path  as a lens, yielding a … l Fold over a [ €! with access to the current path  as a lens. †CNB: The Eq requirement on this instance is a consequence of a lens  rather than e as the representation. XYZ[\]^_`abcdefghijkl†‡XYZ[\]^_`abcdefghijkl[\]^_`abXYZcdklefghijXYZ[\]^_`abcdefghijkl†‡ˆ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]]^_`abcdefghijklmnopqrstuvtwxtuyz{|z}~z€z‚ƒ„…†‡ˆ‰Š‹ŒŽŒŒ‘Œ’Œ“”Œ•–—˜™lens-0.3 Control.LensControl.Lens.RepData.Distributive distribute TraversalFocusfocusFocusing IndexedStore MultiLensMultiLensFamilyGetterSetter SetterFamily LensFamilyLenslensisogetting gettingManysettingreadingmapOf modifyingwriting^$^.^%=^=^+=^-=^*=^/=^||=^&&=clonefstLsndLkeyLintKeyLmemberL intMemberL identityLatLaccess~=%=%%=+=-=*=//=&&=||= foldMapOffoldOffoldrOftoListOfandOforOfanyOfallOf productOfsumOf traverseOf_forOf_ sequenceAOf_mapMOf_forMOf_ sequenceOf_asumOfmsumOfelemOf notElemOf concatMapOfconcatOf traverseOfmapMOf sequenceAOf sequenceOffoldedconstMLheadMLtailMLleftMLrightMLkeyMLintKeyML elementML makeLensesBy makeLenses makeLensesForKeyturn RepresentablerepRepfmapReppureRepapRepbindRep distributeRepkeys mapWithReptraverseWithReptraverseWithRep_ forWithRep mapMWithRep mapMWithRep_ forMWithRepfoldMapWithRep foldrWithRep MultiGetterMultiGetterFamily GetterFamilyghc-prim GHC.Classes|| GHC.TypesBool&&containers-0.4.2.1Data.MapMap Data.IntMapIntMapData.SetSet Data.IntSetIntSet$fFocusReaderT$fMonoidTraversal$fApplicativeSA $fFunctorSA $fFocusStateT$fFocusStateT0$fApplicativeFocusing$fFunctorFocusing$fFunctorIndexedStorebaseGHC.BaseFunctorfmapControl.ApplicativepurereturnData.TraversablemapM Data.MonoidMonoid$fRepresentable(->)$fRepresentableIdentity