ob      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                     !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~    !!!!""##$$$$%&&&&' Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered Used to find the nth ' of a (. !The result of trying to find the nth ' of a (.  Used for  )  Used for  * Used internally by + and the like. Used internally by , and the like. Applicative composition of -.  with a , used  by /, 0, 1, 2 0The indexed store can be used to characterize a  3  and is used by  4 Used by  5 Obtain the minimum. Obtain the maximum )        "rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered YA function with access to a index. This constructor may be useful when you need to store  a " in a container to avoid ImpredicativeTypes. "*Type alias for passing around polymorphic # functions that can be called ! or  directly as a function #bPermit overloading of function application for things that also admit a notion of a key or index. Provides overloading for # functions. $Build a function from an # function % Compose an #' function with a non-indexed function. Mnemonically, the <* points to the index we want to preserve. &'Compose a non-indexed function with an # function. Mnemonically, the >* points to the index we want to preserve. 'Remap the index. (Composition of # functions Mnemonically, the  @ and @: points to the fact that we want to preserve the indices. )Composition of #> functions with a user supplied function for combining indexs CUsing an equality witness to avoid potential overlapping instances  and aid dispatch.  !"#$%&'()  !"#$%&'() #$" !(%&)'  !"#$%&'() Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered * type SimpleIso =  6 ++DIsomorphim families can be composed with other lenses using either () and  I from the Prelude or from Control.Category. However, if you compose them  with each other using (2) from the Prelude, they will be dumbed down to a  mere Lens.   import Control.Category  import Prelude hiding ((.),id)  type Iso a b c d = forall k f. (. k,  f) =>  Overloaded k f a b c d,'A concrete data type for isomorphisms. DThis lets you place an isomorphism inside a container without using ImpredicativeTypes. .7Used to provide overloading of isomorphism application  This is a ) with a canonical mapping to it from the . category of isomorphisms over Haskell types. /*Build this morphism out of an isomorphism The intention is that by using /#, you can supply both halves of an + isomorphism, but k can be instantiated to (->), so you can freely use * the resulting isomorphism as a function. 0MMap a morphism in the target category using an isomorphism between morphisms  in Hask. 1Invert an isomorphism. ENote to compose an isomorphism and receive an isomorphism in turn you'll need to use     from (from l) = l If you imported  from Control.Category, then:  from l . from r = from (r . l) 2Convert from an , back to any . value. WThis is useful when you need to store an isomoprhism as a data type inside a container 6 and later reconstitute it as an overloaded function. 3@Build an isomorphism family from two pairs of inverse functions    view (3 ac ca bd db) = ac  view (1 (3 ac ca bd db)) = ca  set (3 ac ca bd db) cd = db . cd . ac  set (1 (3 ac ca bd db')) ab = bd . ab . ca  8isos :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> + a b c d4<Build a simple isomorphism from a pair of inverse functions    view (4 f g) = f  view (1 (4 f g)) = g  set (3 f g) h = g . h . f  set (1 (4 f g')) h = f . h . g  iso :: (a -> b) -> (b -> a) ->  6 + a b5:This isomorphism can be used to wrap or unwrap a value in .   x^.identity =  x   x ^. 1 5 = x 6:This isomorphism can be used to wrap or unwrap a value in    x ^. 6 =  x   x ^. 1 6 = x *+,-./0123456 *+,-./0123456 ./0,-4312+*65 *+,-./0123456 Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered(77 is just a renamed  functor to give better error = messages when someone attempts to use a getter as a setter. 1Most user code will never need to see this type. : Anything : must be isomorphic to the  . <0This is a useful alias for use when consuming a =. 1Most user code will never have to use this type. type < m =  6 >=A Simple Setter is just a ? that doesn't change the types. NThese are particularly common when talking about monomorphic containers. e.g.  A Data.Text.map :: = 78  type = =  6 ?> Running a ?% instantiates it to a concrete type. WWhen consuming a setter directly to perform a mapping, you can use this type, but most + user code will not need to use this type.  By choosing 7 rather than , we get nicer error messages. ? The only  3-like law that can apply to a ? l is that  D l c (D l b a) = D l c aYou can't view a ?3 in general, so the other two laws are irrelevant.  However, two  laws apply to a ?:    B l id = id  B l f . B l g = B l (f . g) "These an be stated more directly:    l  =   l f . ; . l g = l (f . ; . g) You can compose a ? with a  3 or a ( using () from the Prelude ! and the result is always only a ? and nothing more. @;This setter can be used to map over all of the values in a .    = B @  9: = B 9;  () = D @ A)Build a Setter from a map-like function. Your supplied function f is required to satisfy:    f  =   f g  f h = f (g  h) Equational reasoning:    A . B =   B . A =  Another way to view A is that it takes a "semantic editor combinator"  and transforms it into a ?. BModify the target of a  3 or all the targets of a ? or (  with a function.     = B @  9: = B 9;  A . B =   B . A =  Another way to view B" is to say that it transformers a ? into a  "semantic editor combinator". B :: ? a b c d -> (c -> d) -> a -> bCModify the target of a  3 or all the targets of a ? or ( P with a function. This is an alias for adjust that is provided for consistency.    C = B   = C @   fmapDefault = C traverse  A . C =   C . A =     mapOf :: ?$ a b c d -> (c -> d) -> a -> b  mapOf :: <' a b c d -> (c -> d) -> a -> b  mapOf ::  3& a b c d -> (c -> d) -> a -> b  mapOf :: (! a b c d -> (c -> d) -> a -> b DReplace the target of a  3 or all of the targets of a ?  or ( with a constant value.  () = D @import Control.Lensset _2 "hello" (1,()) (1,"hello")set mapped () [1,2,3,4] [(),(),(),()]Note: Attempting to D a Fold or Getter$ will fail at compile time with an  relatively nice error message.   set :: ? a b c d -> d -> a -> b  set :: < a b c d -> d -> a -> b  set ::  3 a b c d -> d -> a -> b  set :: ( a b c d -> d -> a -> b EModifies the target of a  3 or all of the targets of a ? or  ( with a user supplied function. This is an infix version of B     f = @ E f  9: f = traverse E f import Control.Lens_2 %~ length $ (1,"hello")(1,5)   (%~) :: ?" a b c d -> (c -> d) -> a -> b  (%~) :: <% a b c d -> (c -> d) -> a -> b  (%~) ::  3$ a b c d -> (c -> d) -> a -> b  (%~) :: ( a b c d -> (c -> d) -> a -> b FReplace the target of a  3 or all of the targets of a ?  or ( with a constant value. This is an infix version of D!, provided for consistency with (R)  f  a = @ F f  aimport Control.Lens_1 .~ "hello" $ (42,"world")("hello","world")   (.~) :: ? a b c d -> d -> a -> b  (.~) :: < a b c d -> d -> a -> b  (.~) ::  3 a b c d -> d -> a -> b  (.~) :: ( a b c d -> d -> a -> b GSet with pass-through WThis is mostly present for consistency, but may be useful for for chaining assignments AIf you do not need a copy of the intermediate result, then using l .~ d directly is a good idea.   (<.~) :: ? a b c d -> d -> a -> (d, b)  (<.~) :: <# a b c d -> d -> a -> (d, b)  (<.~) ::  3" a b c d -> d -> a -> (d, b)  (<.~) :: ( a b c d -> d -> a -> (d, b) H0Increment the target(s) of a numerically valued  3, ? or ( import Control.Lens_1 +~ 1 $ (1,2)(2,2)   (+~) :: Num c => ? a b c c -> c -> a -> b  (+~) :: Num c => < a b c c -> c -> a -> b  (+~) :: Num c =>  3 a b c c -> c -> a -> b  (+~) :: Num c => ( a b c c -> c -> a -> b I/Multiply the target(s) of a numerically valued  3, <, ? or ( import Control.Lens_2 *~ 4 $ (1,2)(1,8)   (*~) ::  c => ? a b c c -> c -> a -> b  (*~) ::  c => < a b c c -> c -> a -> b  (*~) ::  c =>  3 a b c c -> c -> a -> b  (*~) ::  c => ( a b c c -> c -> a -> b J0Decrement the target(s) of a numerically valued  3, <, ? or ( import Control.Lens_1 -~ 2 $ (1,2)(-1,2)   (-~) ::  c => ? a b c c -> c -> a -> b  (-~) ::  c => < a b c c -> c -> a -> b  (-~) ::  c =>  3 a b c c -> c -> a -> b  (-~) ::  c => ( a b c c -> c -> a -> b K-Divide the target(s) of a numerically valued  3, <, ? or (   (~) ::  c => ? a b c c -> c -> a -> b  (~) ::  c => < a b c c -> c -> a -> b  (~) ::  c =>  3 a b c c -> c -> a -> b  (~) ::  c => ( a b c c -> c -> a -> b L,Raise the target(s) of a numerically valued  3, ? or (" to a non-negative integral power import Control.Lens_2 ^~ 2 $ (1,3)(1,9)M-Raise the target(s) of a fractionally valued  3, ? or ( to an integral power import Control.Lens_2 ^^~ (-1) $ (1,2)(1,0.5)   (^^~) :: ( c,  e) => ? a b c c -> e -> a -> b  (^^~) :: ( c,  e) => < a b c c -> e -> a -> b  (^^~) :: ( c,  e) =>  3 a b c c -> e -> a -> b  (^^~) :: ( c,  e) => ( a b c c -> e -> a -> b N/Raise the target(s) of a floating-point valued  3, ? or ( to an arbitrary power. import Control.Lens_2 **~ pi $ (1,3)(1,31.54428070019754)   (**~) ::  c => ? a b c c -> c -> a -> b  (**~) ::  c => < a b c c -> c -> a -> b  (**~) ::  c =>  3 a b c c -> c -> a -> b  (**~) ::  c => ( a b c c -> c -> a -> b O Logically  the target(s) of a -valued  3 or ?  :m + Control.Lens Data.Pair.Lensboth ||~ True $ (False,True) (True,True)both ||~ False $ (False,True) (False,True)   (||~):: ? a b   ->  -> a -> b  (||~):: < a b   ->  -> a -> b  (||~)::  3 a b   ->  -> a -> b  (||~):: ( a b   ->  -> a -> b P Logically  the target(s) of a -valued  3 or ?  :m + Control.Lens Data.Pair.Lensboth &&~ True $ (False, True) (False,True)both &&~ False $ (False, True) (False,False)   (&&~):: ? a b   ->  -> a -> b  (&&~):: < a b   ->  -> a -> b  (&&~)::  3 a b   ->  -> a -> b  (&&~):: ( a b   ->  -> a -> b Q,Modify the target of a monoidally valued by ing another value.  :m + Control.Lens Data.Pair.Lens"both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")   ( ~) ::  c => ? a b c c -> c -> a -> b  ( ~) ::  c => < a b c c -> c -> a -> b  ( ~) ::  c =>  3 a b c c -> c -> a -> b  ( ~) ::  c => ( a b c c -> c -> a -> b RReplace the target of a  3 or all of the targets of a ? or ( in our monadic 2 state with a new value, irrespective of the old.    (.=) ::  a m => <" a a c d -> d -> m ()  (.=) ::  a m =>  3! a a c d -> d -> m ()  (.=) ::  a m => ( a a c d -> d -> m ()  (.=) ::  a m => ? a a c d -> d -> m () 9It puts the state in the monad or it gets the hose again. SMap over the target of a  3 or all of the targets of a ? or ( in our monadic state.   (%=) ::  a m => <) a a c d -> (c -> d) -> m ()  (%=) ::  a m =>  3( a a c d -> (c -> d) -> m ()  (%=) ::  a m => (# a a c d -> (c -> d) -> m ()  (%=) ::  a m => ?& a a c d -> (c -> d) -> m () TModify the target(s) of a  6  3, <, ? or ( by adding a value  Example:   $ fresh :: MonadState Int m => m Int  fresh = do   T 1  use     (+=) :: ( a m,  b) =>  6 ? a b -> b -> m ()  (+=) :: ( a m,  b) =>  6 < a b -> b -> m ()  (+=) :: ( a m,  b) =>  6  3 a b -> b -> m ()  (+=) :: ( a m,  b) =>  6 ( a b -> b -> m () UModify the target(s) of a  6  3, <, ? or ( by subtracting a value   (-=) :: ( a m,  b) =>  6 ? a b -> b -> m ()  (-=) :: ( a m,  b) =>  6 < a b -> b -> m ()  (-=) :: ( a m,  b) =>  6  3 a b -> b -> m ()  (-=) :: ( a m,  b) =>  6 ( a b -> b -> m () VModify the target(s) of a  6  3, <, ? or ( by multiplying by value.   ballSpeed  = V speedMultiplier   (*=) :: ( a m,  b) =>  6 ? a b -> b -> m ()  (*=) :: ( a m,  b) =>  6 < a b -> b -> m ()  (*=) :: ( a m,  b) =>  6  3 a b -> b -> m ()  (*=) :: ( a m,  b) =>  6 ( a b -> b -> m () WModify the target(s) of a  6  3, <, ? or ( by dividing by a value.   (=) :: ( a m,  b) =>  6 ? a b -> b -> m ()  (=) :: ( a m,  b) =>  6 < a b -> b -> m ()  (=) :: ( a m,  b) =>  6  3 a b -> b -> m ()  (=) :: ( a m,  b) =>  6 ( a b -> b -> m () X,Raise the target(s) of a numerically valued  3, ? or (# to a non-negative integral power.   (^=) :: ( a m,  b,  c) =>  6 ? a b -> c -> m ()  (^=) :: ( a m,  b,  c) =>  6 < a b -> c -> m ()  (^=) :: ( a m,  b,  c) =>  6  3 a b -> c -> m ()  (^=) :: ( a m,  b,  c) =>  6 ( a b -> c -> m () Y,Raise the target(s) of a numerically valued  3, ? or ( to an integral power.   (^^=) :: ( a m,  b,  c) =>  6 ? a b -> c -> m ()  (^^=) :: ( a m,  b,  c) =>  6 < a b -> c -> m ()  (^^=) :: ( a m,  b,  c) =>  6  3 a b -> c -> m ()  (^^=) :: ( a m,  b,  c) =>  6 ( a b -> c -> m () Z,Raise the target(s) of a numerically valued  3, ? or ( to an arbitrary power   (**=) :: ( a m,  b) =>  6 ? a b -> b -> m ()  (**=) :: ( a m,  b) =>  6 < a b -> b -> m ()  (**=) :: ( a m,  b) =>  6  3 a b -> b -> m ()  (**=) :: ( a m,  b) =>  6 ( a b -> b -> m () [Modify the target(s) of a  6  3, <, ? or ( by taking their logical  with a value   (&&=)::  a m =>  6 ? a  ->  -> m ()  (&&=)::  a m =>  6 < a  ->  -> m ()  (&&=)::  a m =>  6  3 a  ->  -> m ()  (&&=)::  a m =>  6 ( a  ->  -> m () \Modify the target(s) of a  6  3, 'Iso, ? or ( by taking their logical  with a value   (||=)::  a m =>  6 ? a  ->  -> m ()  (||=)::  a m =>  6 < a  ->  -> m ()  (||=)::  a m =>  6  3 a  ->  -> m ()  (||=)::  a m =>  6 ( a  ->  -> m () ]Modify the target(s) of a  6  3, <, ? or ( by  ing a value.   ( =) :: ( a m,  b) =>  6 ? a b -> b -> m ()  ( =) :: ( a m,  b) =>  6 < a b -> b -> m ()  ( =) :: ( a m,  b) =>  6  3 a b -> b -> m ()  ( =) :: ( a m,  b) =>  6 ( a b -> b -> m () ^6Run a monadic action, and set all of the targets of a  3, ? or ( to its result.    (<~) ::  a m => < a a c d -> m d -> m ()  (<~) ::  a m =>  3 a a c d -> m d -> m ()  (<~) ::  a m => ( a a c d -> m d -> m ()  (<~) ::  a m => ? a a c d -> m d -> m () cAs a reasonable mnemonic, this lets you store the result of a monadic action in a lens rather than  in a local variable.   do foo <- bar  ... +will store the result in a variable, while   do foo <~ bar  ... will store the result in a  3, ?, or (. _Set with pass-through XThis is useful for chaining assignment without round-tripping through your monad stack.  do x <- _2 <*.= ninety_nine_bottles_of_beer_on_the_wallAIf you do not need a copy of the intermediate result, then using l .= d$ will avoid unused binding warnings   (<.=) ::  a m => ? a a c d -> d -> m d  (<.=) ::  a m => < a a c d -> d -> m d  (<.=) ::  a m =>  3 a a c d -> d -> m d  (<.=) ::  a m => ( a a c d -> d -> m d  > so you can pass our a ?, into combinators from other lens libraries /789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_)?:;A@BCDFEHJIKLMNOPQGRSTUVWXYZ\[]_^>789<=,789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered`Used instead of  to report  No instance of (? `)#when the user attempts to misuse a @ as a f, - rather than a monolithic unification error. c Generalizing  so we can apply simple  transformations to it ( and so we can get nicer error messages A c < ignores its argument, which it carries solely as a phantom  type parameter. To ensure this, an instance of c is required to satisfy:  =  f = dd#Replace the phantom type argument. eMost f- combinators are able to be used with both a f or a  A in S limited situations, to do so, they need to be monomorphic in what we are going to  extract with . To be compatible with  3, ( and < we also : restricted choices of the irrelevant b and d parameters. If a function accepts a e r a c , then when r is a , then you can pass a  A (or (&), otherwise you can only pass this a  f or  3. fA fM describes how to retrieve a single value in a way that can be composed with  other lens-like constructions.  Unlike a  3 a f is read-only. Since a f cannot be used to write back k there are no lens laws that can be applied to it. In fact, it is isomorphic to an arbitrary function from (a -> c).  Moreover, a f can be used directly as a  A, since it just ignores the . gBuild a f% from an arbitrary Haskell function.  g f . g g = g (g . f) a k g f = f aimport Control.Lens(0, -5)^._2.to abs5hView the value pointed to by a f, < or  3 or the result of folding over  all the results of a  A or (# that points at a monoidal values. It may be useful to think of h. as having these more restrictive signatures:  h . g = import Control.Lensview _2 (1,"hello")"hello"   view :: f a c -> a -> c  view ::  m =>  A a m -> a -> m  view ::  6 < a c -> a -> c  view ::  6  3 a c -> a -> c  view ::  m =>  6 ( a m -> a -> m iView the value of a f, <,  3# or the result of folding over the $ result of mapping the targets of a  A or (. It may be useful to think of i. as having these more restrictive signatures: import Control.Lensviews _2 length (1,"hello")5   views :: f' a c -> (c -> d) -> a -> d  views ::  m =>  A) a c -> (c -> m) -> a -> m  views ::  6 <# a c -> (c -> d) -> a -> d  views ::  6  3" a c -> (c -> d) -> a -> d  views ::  m =>  6 ( a c -> (c -> m) -> a -> m jView the value pointed to by a f, < or  3 or the result of folding over  all the results of a  A or (# that points at a monoidal values. This is the same operation as h, only infix. import Control.Lens_2 ^$ (1, "hello")"hello"   (^$) :: f a c -> a -> c  (^$) ::  m =>  A a m -> a -> m  (^$) ::  6 < a c -> a -> c  (^$) ::  6  3 a c -> a -> c  (^$) ::  m =>  6 ( a m -> a -> m kView the value pointed to by a f or  3 or the result of folding over  all the results of a  A or (# that points at a monoidal values. This is the same operation as h with the arguments flipped. HThe fixity and semantics are such that subsequent field accesses can be  performed with () :m + Data.Complex Control.Lens$((0, 1 :+ 2), 3)^._1._2.to magnitude2.23606797749979   (^.) :: a -> f a c -> c  (^.) ::  m => a ->  A a m -> m  (^.) :: a ->  6 < a c -> c  (^.) :: a ->  6  3 a c -> c  (^.) ::  m => a ->  6 ( a m -> m lQuery the target of a  3, < or f in the current state, or use a  summary of a  A or (" that points to a monoidal value.   query ::  a m => f a c -> m c  query :: ( a m,  c) =>  A a c -> m c  query ::  a m =>  6 < a c -> m c  query ::  a m =>  6  3 a c -> m c  query :: ( a m,  c) =>  6 ( a c -> m c mUse the target of a  3, < or f in the current state, or use a  summary of a  A or (" that points to a monoidal value.   queries ::  a m => f" a c -> (c -> e) -> m e  queries :: ( a m,  c) =>  A$ a c -> (c -> e) -> m e  queries ::  a m =>  6 < a c -> (c -> e) -> m e  queries ::  a m =>  6  3 a c -> (c -> e) -> m e  queries :: ( a m,  c) =>  6 ( a c -> (c -> e) -> m e nUse the target of a  3, <, or f in the current state, or use a  summary of a  A or (" that points to a monoidal value.   use ::  a m => f a c -> m c  use :: ( a m,  r) =>  A a r -> m r  use ::  a m =>  6 < a c -> m c  use ::  a m =>  6  3 a c -> m c  use :: ( a m,  r) =>  6 ( a r -> m r oUse the target of a  3, < or f in the current state, or use a  summary of a  A or (" that points to a monoidal value.   uses ::  a m => f" a c -> (c -> e) -> m e  uses :: ( a m,  r) =>  A$ a c -> (c -> r) -> m r  uses ::  a m =>  6  3 a c -> (c -> e) -> m e  uses ::  a m =>  6 < a c -> (c -> e) -> m e  uses :: ( a m,  r) =>  6 ( a c -> (c -> r) -> m r 0This instance is a lie, but it is a useful lie. `abcdefghijklmno`abcdefghijklmnofecd`abgkjhinolm`abcdefghijklmnoMTPCs, FDs, Rank2 experimentalEdward Kmett <ekmett@gmail.com> Safe-Infered pUsed to evaluate an w. q4Wrap a monadic effect with a phantom type argument. tAn t K ignores its argument and is isomorphic to a monad wrapped around a value. 9That said, the monad is possibly rather unrelated to any  structure. vA v is a Fold enriched with access to a  for side-effects. Every Fold can be used as a v(, that simply ignores the access to the . You can compose a v with another v using ( ) from the Prelude. wAn w is a f enriched with access to a  for side-effects. Every f can be used as an w You can compose an w with another w using ( ) from the Prelude. x.A convenient antonym that is used internally. y Perform an w.  perform = flip (^!) z Perform an w import Control.Lens&["hello","world"]^!folded.act putStrLnhelloworld{ Construct an w from a monadic side-effect |A self-running w, analogous to .  | = { import Control.Lens(1,"hello")^!_2.acts.to succ"ifmmp"}Apply a  transformer to an w. pqrstuvwxyz{|}pqrstuvwxyz{|}w{|y}zvptuxqrspqrstuvwxyz{|}rank 2 types, MPTCs experimentalEdward Kmett <ekmett@gmail.com> Safe-Infered~Used to consume an  B. Every  is a valid  B and f. ~~~~ "rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedEvery  is a valid  A. Fold an  or  C/ by mapping indices and values to an arbitrary  with access  to the index i.  When you don' t need access to the index then  D& is more flexible in what it accepts.   D l =  l .    ifoldMapOf :: + i a c -> (i -> c -> m) -> a -> m  ifoldMapOf ::  m => - i a c -> (i -> c -> m) -> a -> m  ifoldMapOf ::  E' i a c -> (i -> c -> m) -> a -> m  ifoldMapOf ::  m =>  F" i a c -> (i -> c -> m) -> a -> m JRight-associative fold of parts of a structure that are viewed through an  or  C with  access to the index i.  When you don' t need access to the index then  G& is more flexible in what it accepts.   G l =  l .    ifoldrOf :: 5 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf :: 7 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf ::  E1 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf ::  F, i a c -> (i -> c -> e -> e) -> e -> a -> e MLeft-associative fold of the parts of a structure that are viewed through an  or  C with  access to the index i.  When you don' t need access to the index then  H& is more flexible in what it accepts.   H l =  l .    ifoldlOf :: 5 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf :: 7 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf ::  E1 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf ::  F, i a c -> (i -> e -> c -> e) -> e -> a -> e 4Return whether or not any element viewed through an  or  C / satisfy a predicate, with access to the index i.  When you don' t need access to the index then  I& is more flexible in what it accepts.   I l =  l .    ianyOf ::  i a c -> (i -> c ->  ) -> a ->   ianyOf ::  i a c -> (i -> c ->  ) -> a ->   ianyOf ::  E i a c -> (i -> c ->  ) -> a ->   ianyOf ::  F i a c -> (i -> c ->  ) -> a ->  5Return whether or not all elements viewed through an  or  C / satisfy a predicate, with access to the index i.  When you don' t need access to the index then  J& is more flexible in what it accepts.   J l =  l .    iallOf ::  i a c -> (i -> c ->  ) -> a ->   iallOf ::  i a c -> (i -> c ->  ) -> a ->   iallOf ::  E i a c -> (i -> c ->  ) -> a ->   iallOf ::  F i a c -> (i -> c ->  ) -> a ->  Traverse the targets of an  or  C with access to the index i, discarding the results.  When you don' t need access to the index then  ,& is more flexible in what it accepts.   , l =  itraverseOf l .    itraverseOf_ ::  f => 0 i a c -> (i -> c -> f e) -> a -> f ()  itraverseOf_ ::  f => 2 i a c -> (i -> c -> f e) -> a -> f ()  itraverseOf_ ::  f =>  E, i a c -> (i -> c -> f e) -> a -> f ()  itraverseOf_ ::  f =>  F' i a c -> (i -> c -> f e) -> a -> f () Traverse the targets of an  or  C2 with access to the index, discarding the results  (with the arguments flipped).   =  .  When you don' t need access to the index then  K& is more flexible in what it accepts.   K l a = iforOf l a .    iforOf_ ::  f => 0 i a c -> a -> (i -> c -> f e) -> f ()  iforOf_ ::  f => 2 i a c -> a -> (i -> c -> f e) -> f ()  iforOf_ ::  f =>  E, i a c -> a -> (i -> c -> f e) -> f ()  iforOf_ ::  f =>  F' i a c -> a -> (i -> c -> f e) -> f () *Run monadic actions for each target of an  or  C with access to the index,  discarding the results.  When you don' t need access to the index then  L& is more flexible in what it accepts.   L l = imapMOf l .    imapMOf_ ::  m => 0 i a c -> (i -> c -> m e) -> a -> m ()  imapMOf_ ::  m => 2 i a c -> (i -> c -> m e) -> a -> m ()  imapMOf_ ::  m =>  E, i a c -> (i -> c -> m e) -> a -> m ()  imapMOf_ ::  m =>  F' i a c -> (i -> c -> m e) -> a -> m () *Run monadic actions for each target of an  or  C with access to the index, 6 discarding the results (with the arguments flipped).   =  .  When you don' t need access to the index then  M& is more flexible in what it accepts.   M l a = iforMOf l a .    iforMOf_ ::  m => 0 i a c -> a -> (i -> c -> m e) -> m ()  iforMOf_ ::  m => 2 i a c -> a -> (i -> c -> m e) -> m ()  iforMOf_ ::  m =>  E, i a c -> a -> (i -> c -> m e) -> m ()  iforMOf_ ::  m =>  F' i a c -> a -> (i -> c -> m e) -> m () <Concatenate the results of a function of the elements of an  or  C  with access to the index.  When you don' t need access to the index then  N' is more flexible in what it accepts.   N l =  iconcatMapMOf l .    iconcatMapOf ::  i a c -> (i -> c -> [e] ) -> a -> [e]  iconcatMapOf :: " i a c -> (i -> c -> [e] ) -> a -> [e]  iconcatMapOf ::  E i a c -> (i -> c -> [e] ) -> a -> [e]  iconcatMapOf ::  F i a c -> (i -> c -> [e] ) -> a -> [e] The findOf function takes an  or  C, a predicate that is also T supplied the index, a structure and returns the left-most element of the structure  matching the predicate, or  if there is no such element.  When you don' t need access to the index then  O& is more flexible in what it accepts.   O l = ifoldOf l .    ifindOf ::  a c -> (i -> c ->  ) -> a ->  (i, c)  ifindOf ::  a c -> (i -> c ->  ) -> a ->  (i, c)  ifindOf ::  E a c -> (i -> c ->  ) -> a ->  (i, c)  ifindOf ::  F a c -> (i -> c ->  ) -> a ->  (i, c) Strictly< fold right over the elements of a structure with an index.  When you don' t need access to the index then  P& is more flexible in what it accepts.   P l =  l .    ifoldrOf' :: 5 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf' :: 7 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf' ::  E1 i a c -> (i -> c -> e -> e) -> e -> a -> e  ifoldrOf' ::  F, i a c -> (i -> c -> e -> e) -> e -> a -> e RFold over the elements of a structure with an index, associating to the left, but strictly.  When you don' t need access to the index then  Q& is more flexible in what it accepts.   Q l =  l .    ifoldlOf' :: 7 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf' :: 9 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf' ::  E3 i a c -> (i -> e -> c -> e) -> e -> a -> e  ifoldlOf' ::  F. i a c -> (i -> e -> c -> e) -> e -> a -> e CMonadic fold right over the elements of a structure with an index.  When you don' t need access to the index then  R& is more flexible in what it accepts.   R l =  l .    ifoldrMOf ::  m => 7 i a c -> (i -> c -> e -> m e) -> e -> a -> e  ifoldrMOf ::  m => 9 i a c -> (i -> c -> e -> m e) -> e -> a -> e  ifoldrMOf ::  m =>  E3 i a c -> (i -> c -> e -> m e) -> e -> a -> e  ifoldrMOf ::  m =>  F. i a c -> (i -> c -> e -> m e) -> e -> a -> e VMonadic fold over the elements of a structure with an index, associating to the left.  When you don' t need access to the index then  S& is more flexible in what it accepts.   S l =  l .    ifoldlOf' ::  m => 9 i a c -> (i -> e -> c -> m e) -> e -> a -> e  ifoldlOf' ::  m => ; i a c -> (i -> e -> c -> m e) -> e -> a -> e  ifoldlOf' ::  m =>  E5 i a c -> (i -> e -> c -> m e) -> e -> a -> e  ifoldlOf' ::  m =>  F0 i a c -> (i -> e -> c -> m e) -> e -> a -> e .Extract the key-value pairs from a structure.  When you don'1t need access to the indices in the result, then  T& is more flexible in what it accepts.   T l =   .  l   itoListOf ::  i a c -> a -> [(i,c)]  itoListOf ::  i a c -> a -> [(i,c)]  itoListOf ::  E i a c -> a -> [(i,c)]  itoListOf ::  F i a c -> a -> [(i,c)]  Obtain an  by filtering a  U, ,  or  C.  Obtain an ! by taking elements from another ,  U,  or  C while a predicate holds.  Obtain an # by dropping elements from another ,  U,  or  C while a predicate holds.   Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered:,Provides access to the 9th field of a tuple  Access the 9th field of a tuple +Provide access to the 8th field of a tuple  Access the 8th field of a tuple +Provide access to the 7th field of a tuple  Access the 7th field of a tuple .Provides access to the 6th element of a tuple  Access the 6th field of a tuple ,Provides access to the 5th field of a tuple  Access the 5th field of a tuple +Provide access to the 4th field of a tuple  Access the 4th field of a tuple ,Provides access to the 3rd field of a tuple  Access the 3rd field of a tuple ,Provides access to the 2nd field of a tuple  Access the 2nd field of a tuple import Control.Lens_2 .~ "hello" $ (1,(),3,4)(1,"hello",3,4)    I  :: (c -> ) -> (a, c) ->   9;   :: ( f, 9V. t) => (a -> f b) -> t (c, a) -> f (t (c, b))   D (9;  ) :: (9V t, ! m) => (c -> m) -> t (b, c) -> m )Provides access to 1st field of a tuple. @Access the 1st field of a tuple (and possibly change its type). import Control.Lens (1,2)^._11_1 .~ "hello" $ (1,2) ("hello",2)/This can also be used on larger tuples as well _1 +~ 41 $ (1,2,3,4,5) (42,2,3,4,5)   _1 ::  (a,b) (a',b) a a'  _1 ::  (a,b,c) (a' ,b,c) a a'  _1 ::  (a,b,c,d) (a' ,b,c,d) a a'  ...  _1 ::  (a,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'  type  k f a b =  ( k f) a b type  f a b c d =  (->) f a b c dThis class allows us to use . on a number of different monad transformers. IRun a monadic action in a larger context than it was defined in, using a   or  (. lThis is commonly used to lift actions in a simpler state monad into a state monad with a larger state type. When applied to a 'Simple (M over multiple values, the actions for each target are executed sequentially + and the results are aggregated monoidally  and a monoidal summary  of the result is given.   focus ::  m =>  <# a b -> st b m c -> st a m c  focus ::  m =>  " a b -> st b m c -> st a m c  focus :: ( m,  c) =>  ( a b -> st b m c -> st a m c Like 4, but discarding any accumulated results as you go.   focus_ ::  m =>  <$ a b -> st b m c -> st a m ()  focus_ ::  m =>  # a b -> st b m c -> st a m ()  focus_ :: ( m,  c) =>  ( a b -> st b m c -> st a m () A much more limited version of  that can work with a ?. Many combinators that accept a  can also accept a ( in limited situations. 'They do so by specializing the type of " that they require of the caller. If a function accepts a  f a b c d for some  f, then they may be passed a .  Further, if f is an , they may also be passed a (. type  f =  ( f) type  =  A  ,  (, ... can be used instead of a ,(, ...  whenever the type variables don't change upon setting a value.    W ::   (XY a) a  Z ::  [( [a] a .Note: To use this alias in your own code with  f or ?, you may have to turn on  LiberalTypeSynonyms. A + is actually a lens family as described in  /http://comonad.com/reader/2012/mirrored-lenses/. 2With great power comes great responsibility and a 1 is subject to the three common sense lens laws: !1) You get back what you put in:  view l (D l b a) = b"2) Putting back what you got doesn't change anything:  D l (view l a) a = a.3) Setting twice is the same as setting once:  D l c (D l b a) = D l c a=These laws are strong enough that the 4 type parameters of a . 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 directly as a ? or (. You can also use a  for \ as if it were a  A or Getter. Since every lens is a valid (A, the traversal laws should also apply to any lenses you create.  ) Idiomatic naturality:  l  =  ) Sequential composition:   (l f) . l g = ]^ . l (]_ .  f . g) type  a b c d = forall f.  f =>  f a b c dBuild a  from a getter and a setter. J lens :: Functor f => (a -> c) -> (a -> d -> b) -> (c -> f d) -> a -> f b (') can be used in one of two scenarios: When applied to a  , it can edit the target of the  in a structure, extracting a  functorial result. When applied to a (!, it can edit the targets of the  Traversals, extracting an % applicative summary of its actions. 8For all that the definition of this combinator is just:  () =    (%%~) ::  f => <) a b c d -> (c -> f d) -> a -> f b  (%%~) ::  f => ( a b c d -> (c -> f d) -> a -> f b  (%%~) ::  f => (# a b c d -> (c -> f d) -> a -> f b `It may be beneficial to think about it as if it had these even more restrictive types, however: When applied to a (!, it can edit the targets of the  Traversals, extracting a G supplemental monoidal summary of its actions, by choosing f = ((,) m)   (%%~) :: </ a b c d -> (c -> (e, d)) -> a -> (e, b)  (%%~) :: . a b c d -> (c -> (e, d)) -> a -> (e, b)  (%%~) ::  m => () a b c d -> (c -> (m, d)) -> a -> (m, b) Modify the target of a : in the current state returning some extra information of c or  modify all targets of a (< in the current state, extracting extra information of type c / and return a monoidal summary of the changes.  () = ( )It may be useful to think of (>), instead, as having either of the following more restricted  type signatures:   (%%=) ::  a m => <& a a c d -> (c -> (e, d) -> m e  (%%=) ::  a m => % a a c d -> (c -> (e, d) -> m e  (%%=) :: ( a m,  e) => ( a a c d -> (c -> (e, d) -> m e HThis lens can be used to change the result of a function but only where $ the arguments match the key given. 9Merge two lenses, getters, setters, folds or traversals.  makes a ) from two other lenses (or isomorphisms)  Cloning a ) is one way to make sure you arent given  something weaker, such as a ( and can be used ? as a way to pass around lenses that have to be monomorphic in f. !Note: This only accepts a proper  , because  lacks its  (admissable)  instance. "/Costate Comonad Coalgebra is equivalent of Java'/s member variable update technology for Haskell"  -- @PLT_Borat on Twitter Modify the target of a  and return the result 2When you do not need the result of the addition, (H) is more flexible. -Increment the target of a numerically valued  and return the result 2When you do not need the result of the addition, (H) is more flexible. -Decrement the target of a numerically valued  and return the result 5When you do not need the result of the subtraction, (J) is more flexible. ,Multiply the target of a numerically valued  and return the result 8When you do not need the result of the multiplication, (I) is more flexible. +Divide the target of a fractionally valued  and return the result. 2When you do not need the result of the division, (K) is more flexible. )Raise the target of a numerically valued  to a non-negative  power and return the result 2When you do not need the result of the division, (L) is more flexible. *Raise the target of a fractionally valued  to an  power and return the result 2When you do not need the result of the division, (M) is more flexible. ,Raise the target of a floating-point valued - to an arbitrary power and return the result 2When you do not need the result of the division, (N) is more flexible.  Logically  a Boolean valued  and return the result 3When you do not need the result of the operation, (O) is more flexible.  Logically  a Boolean valued  and return the result 3When you do not need the result of the operation, (P) is more flexible. 2 a monoidal value onto the end of the target of a  and return the result 3When you do not need the result of the operation, (Q) is more flexible. Modify the target of a  into your monad';s state by a user supplied function and return the result. 3When you do not need the result of the operation, (S) is more flexible. *Add to the target of a numerically valued  into your monad's state and return the result. 8When you do not need the result of the multiplication, (T) is more flexible. 1Subtract from the target of a numerically valued  into your monad's state and return the result. 8When you do not need the result of the multiplication, (U) is more flexible. ,Multiply the target of a numerically valued  into your monad's state and return the result. 8When you do not need the result of the multiplication, (V) is more flexible. +Divide the target of a fractionally valued  into your monad's state and return the result. 2When you do not need the result of the division, (W) is more flexible. )Raise the target of a numerically valued  into your monad's state to a non-negative  power and return the result 3When you do not need the result of the operation, (Z) is more flexible. *Raise the target of a fractionally valued  into your monad's state to an  power and return the result 3When you do not need the result of the operation, (Y) is more flexible. ,Raise the target of a floating-point valued  into your monad'4s state to an arbitrary power and return the result 3When you do not need the result of the operation, (Z) is more flexible.  Logically  a Boolean valued  into your monad's state and return the result 3When you do not need the result of the operation, (\) is more flexible.  Logically  a Boolean valued  into your monad's state and return the result 3When you do not need the result of the operation, ([) is more flexible. 2 a monoidal value onto the end of the target of a  into your monad's state and return the result 3When you do not need the result of the operation, (]) is more flexible. i      !"#$%&'::]      !"#$%&'  Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered2A I describes how to retrieve multiple values in a way that can be composed % with other lens-like constructions. A  a cC provides a structure with operations very similar to those of the (  typeclass, see  and the other  combinators. !By convention, if there exists a foo method that expects a ( (f c), then there should be a  fooOf method that takes a  a c and a value of type a. A f is a legal  that just ignores the supplied   Unlike a ( a  is read-only. Since a  cannot be used to write back $ there are no lens laws that apply.  Obtain a 9 by lifting an operation that returns a foldable result. +This can be useful to lift operations from  Data.List and elsewhere into a .  Obtain a  from any (. %Fold by repeating the input forever. ) =  !A fold that replicates its input n times. * n =  ( n)ITransform a fold into a fold that loops over its elements over and over. import Control.Lens+take 6 $ toListOf (cycled traverse) [1,2,3] [1,2,3,1,2,3]2Build a fold that unfolds its values from a seed. `a =  . x ^.  f5 Return an infinite fold of repeated applications of f to x. ' toListOf (iterated f) a = iterate f a  Obtain a  by filtering a , <, f,  or (. .This allows you to traverse the elements of a ( or  in the opposite order. Note:  should have no impact on a f Setter,  or <. To change the direction of an <, use from.  Obtain a ! by taking elements from another , , <, f or ( while a predicate holds.  + p =  ( p ))toListOf (takingWhile (<=3) folded) [1..][1,2,3] Obtain a # by dropping elements from another , , <, f or ( while a predicate holds.  , p =  ( p ),toListOf (droppingWhile (<=3) folded) [1..6][4,5,6] bc =    = i   foldMapOf :: f% a c -> (c -> r) -> a -> r  foldMapOf ::  r => ' a c -> (c -> r) -> a -> r  foldMapOf ::   a c -> (c -> r) -> a -> r  foldMapOf ::  <! a c -> (c -> r) -> a -> r  foldMapOf ::  r =>  ( a c -> (c -> r) -> a -> r  bd =    = h   foldOf :: f a m -> a -> m  foldOf ::  m =>  a m -> a -> m  foldOf ::   a m -> a -> m  foldOf ::  < a m -> a -> m  foldOf ::  m =>  ( a m -> a -> m IRight-associative fold of parts of a structure that are viewed through a , f,  or (.  be =     foldrOf :: f/ a c -> (c -> e -> e) -> e -> a -> e  foldrOf :: 1 a c -> (c -> e -> e) -> e -> a -> e  foldrOf ::  * a c -> (c -> e -> e) -> e -> a -> e  foldrOf ::  <+ a c -> (c -> e -> e) -> e -> a -> e  foldrOf ::  (% a c -> (c -> e -> e) -> e -> a -> e LLeft-associative fold of the parts of a structure that are viewed through a , f,  or (.  bf =     foldlOf :: f/ a c -> (e -> c -> e) -> e -> a -> e  foldlOf :: 1 a c -> (e -> c -> e) -> e -> a -> e  foldlOf ::  * a c -> (e -> c -> e) -> e -> a -> e  foldlOf ::  <+ a c -> (e -> c -> e) -> e -> a -> e  foldlOf ::  (% a c -> (e -> c -> e) -> e -> a -> e  bg =     toListOf :: f a c -> a -> [c]  toListOf ::  a c -> a -> [c]  toListOf ::   a c -> a -> [c]  toListOf ::  < a c -> a -> [c]  toListOf ::  ( a c -> a -> [c]  bh =     andOf :: f a  -> a ->   andOf ::  a  -> a ->   andOf ::   a  -> a ->   andOf ::  < a  -> a ->   andOf ::  ( a  -> a ->   bi =     orOf :: f a  -> a ->   orOf ::  a  -> a ->   orOf ::   a  -> a ->   orOf ::  < a  -> a ->   orOf ::  ( a  -> a ->   bj =     anyOf :: f a c -> (c ->  ) -> a ->   anyOf ::  a c -> (c ->  ) -> a ->   anyOf ::   a b c d -> (c ->  ) -> a ->   anyOf ::  < a b c d -> (c ->  ) -> a ->   anyOf ::  ( a b c d -> (c ->  ) -> a ->   bk =     allOf :: f a c -> (c ->  ) -> a ->   allOf ::  a c -> (c ->  ) -> a ->   allOf ::   a c -> (c ->  ) -> a ->   allOf ::  < a c -> (c ->  ) -> a ->   allOf ::  ( a c -> (c ->  ) -> a ->   bl =     productOf :: f a c -> a -> c  productOf ::  c =>  a c -> a -> c  productOf ::   a c -> a -> c  productOf ::  < a c -> a -> c  productOf ::  c =>  ( a c -> a -> c  bm =     :: (a, b) -> a  ( . ) :: (( f,  a) => f (a, b) -> a   sumOf :: f a c -> a -> c  sumOf ::  c =>  a c -> a -> c  sumOf ::   a c -> a -> c  sumOf ::  < a c -> a -> c  sumOf ::  c =>  ( a c -> a -> c When passed a f,  can work over a . When passed a ,  requires an .  bn =     :: # f => (c -> f e) -> (c1, c) -> f ()  o ::  f => (a -> f b) -> - a c -> f ()bThe rather specific signature of traverseOf_ allows it to be used as if the signature was either:   traverseOf_ ::  f => f* a c -> (c -> f e) -> a -> f ()  traverseOf_ ::  f => , a c -> (c -> f e) -> a -> f ()  traverseOf_ ::  f =>  % a c -> (c -> f e) -> a -> f ()  traverseOf_ ::  f =>  <& a c -> (c -> f e) -> a -> f ()  traverseOf_ ::  f =>  ( a c -> (c -> f e) -> a -> f ()  . =     forOf_ ::  f => f* a c -> a -> (c -> f e) -> f ()  forOf_ ::  f => , a c -> a -> (c -> f e) -> f ()  forOf_ ::  f =>  % a c -> a -> (c -> f e) -> f ()  forOf_ ::  f =>  <& a c -> a -> (c -> f e) -> f ()  forOf_ ::  f =>  ( a c -> a -> (c -> f e) -> f ()  / =     sequenceAOf_ ::  f => f! a (f ()) -> a -> f ()  sequenceAOf_ ::  f => # a (f ()) -> a -> f ()  sequenceAOf_ ::  f =>   a (f ()) -> a -> f ()  sequenceAOf_ ::  f =>  Iso a (f ()) -> a -> f ()  sequenceAOf_ ::  f =>  ( a (f ()) -> a -> f ()  b+ =     mapMOf_ ::  m => f* a c -> (c -> m e) -> a -> m ()  mapMOf_ ::  m => , a c -> (c -> m e) -> a -> m ()  mapMOf_ ::  m =>  % a c -> (c -> m e) -> a -> m ()  mapMOf_ ::  m =>  <& a c -> (c -> m e) -> a -> m ()  mapMOf_ ::  m =>  ( a c -> (c -> m e) -> a -> m ()  bp =     forMOf_ ::  m => f* a c -> a -> (c -> m e) -> m ()  forMOf_ ::  m => , a c -> a -> (c -> m e) -> m ()  forMOf_ ::  m =>  % a c -> a -> (c -> m e) -> m ()  forMOf_ ::  m =>  <& a c -> a -> (c -> m e) -> m ()  forMOf_ ::  m =>  ( a c -> a -> (c -> m e) -> m ()  bq =     sequenceOf_ ::  m => f a (m b) -> a -> m ()  sequenceOf_ ::  m => " a (m b) -> a -> m ()  sequenceOf_ ::  m =>   a (m b) -> a -> m ()  sequenceOf_ ::  m =>  < a (m b) -> a -> m ()  sequenceOf_ ::  m =>  ( a (m b) -> a -> m () 1The sum of a collection of actions, generalizing .  0 =     asumOf :: 1 f => f a c -> a -> f c  asumOf :: 1 f =>  a c -> a -> f c  asumOf :: 1 f =>   a c -> a -> f c  asumOf :: 1 f =>  < a c -> a -> f c  asumOf :: 1 f =>  ( a c -> a -> f c 1The sum of a collection of actions, generalizing .  2 =     msumOf :: 3 m => f a c -> a -> m c  msumOf :: 3 m =>  a c -> a -> m c  msumOf :: 3 m =>   a c -> a -> m c  msumOf :: 3 m =>  < a c -> a -> m c  msumOf :: 3 m =>  ( a c -> a -> m c  4 =     elemOf :: 5 c => f a c -> c -> a ->   elemOf :: 5 c =>  a c -> c -> a ->   elemOf :: 5 c =>   a c -> c -> a ->   elemOf :: 5 c =>  < a c -> c -> a ->   elemOf :: 5 c =>  ( a c -> c -> a ->   6 =     notElemOf :: 5 c => f a c -> c -> a ->   notElemOf :: 5 c =>  a c -> c -> a ->   notElemOf :: 5 c =>  < a c -> c -> a ->   notElemOf :: 5 c =>   a c -> c -> a ->   notElemOf :: 5 c =>  ( a c -> c -> a ->   7 =     concatMapOf :: f a c -> (c -> [e] ) -> a -> [e]  concatMapOf ::  a c -> (c -> [e] ) -> a -> [e]  concatMapOf ::   a c -> (c -> [e] ) -> a -> [e]  concatMapOf ::  < a c -> (c -> [e] ) -> a -> [e]  concatMapOf ::  ( a c -> (c -> [e] ) -> a -> [e]    8 =     = h    concatOf :: f a [e] -> a -> [e]  concatOf ::  a [e] -> a -> [e]  concatOf ::  < a [e] -> a -> [e]  concatOf ::   a [e] -> a -> [e]  concatOf ::  ( a [e] -> a -> [e] ;Note: this can be rather inefficient for large containers.  9 =  lengthOf _1 ("hello",())1  ( . ) :: ( f => f (g a) ->    lengthOf :: f a c -> a ->   lengthOf ::  a c -> a ->   lengthOf ::   a c -> a ->   lengthOf ::  < a c -> a ->   lengthOf ::  ( a c -> a ->  Perform a safe : of a  or ( or retrieve ; the result  from a f or .  < . = =     headOf :: f a c -> a ->  c  headOf ::  a c -> a ->  c  headOf ::   a c -> a ->  c  headOf ::  < a c -> a ->  c  headOf ::  ( a c -> a ->  c Perform a safe > of a  or ( or retrieve ; the result  from a f or .   lastOf :: f a c -> a ->  c  lastOf ::  a c -> a ->  c  lastOf ::   a c -> a ->  c  lastOf ::  < a c -> a ->  c  lastOf ::  ( a c -> a ->  c Returns ? if this  or (( has no targets in the given container. Note:  on a valid <,  or f should always return @  A =  /This may be rather inefficient compared to the A check of many containers. nullOf _1 (1,2)False  ( .  . ) :: ( f => f (g a, b) ->    nullOf :: f a c -> a ->   nullOf ::  a c -> a ->   nullOf ::  < a c -> a ->   nullOf ::   a c -> a ->   nullOf ::  ( a c -> a ->  2Obtain the maximum element (if any) targeted by a  or ( Note: maximumOf on a valid <,  or f will always return ; a value.  B = C (D empty) .     maximumOf :: f a c -> a ->  c  maximumOf :: E c =>  a c -> a ->  c  maximumOf ::  < a c -> a ->  c  maximumOf ::   a c -> a ->  c  maximumOf :: E c =>  ( a c -> a ->  c 2Obtain the minimum element (if any) targeted by a  or ( Note: minimumOf on a valid <,  or f will always return ; a value.  F = C (D empty) .     minimumOf :: f a c -> a ->  c  minimumOf :: E c =>  a c -> a ->  c  minimumOf ::  < a c -> a ->  c  minimumOf ::   a c -> a ->  c  minimumOf :: E c =>  ( a c -> a ->  c 2Obtain the maximum element (if any) targeted by a , (, , <,  or f( according to a user supplied ordering.  br cmp = C (D empty) .   cmp   maximumByOf :: f a c -> (c -> c -> G ) -> a ->  c  maximumByOf ::  a c -> (c -> c -> G ) -> a ->  c  maximumByOf ::  < a c -> (c -> c -> G ) -> a ->  c  maximumByOf ::   a c -> (c -> c -> G ) -> a ->  c  maximumByOf ::  ( a c -> (c -> c -> G ) -> a ->  c 2Obtain the minimum element (if any) targeted by a , (, , <  or f( according to a user supplied ordering.  D minimumBy cmp = fromMaybe (error "empty") . minimumByOf folded cmp   minimumByOf :: f a c -> (c -> c -> G ) -> a ->  c  minimumByOf ::  a c -> (c -> c -> G ) -> a ->  c  minimumByOf ::  < a c -> (c -> c -> G ) -> a ->  c  minimumByOf ::   a c -> (c -> c -> G ) -> a ->  c  minimumByOf ::  ( a c -> (c -> c -> G ) -> a ->  c The  function takes a  (or f, <, , or (), O a predicate and a structure and returns the leftmost element of the structure  matching the predicate, or  if there is no such element.   findOf :: f a c -> (c ->  ) -> a ->  c  findOf ::  a c -> (c ->  ) -> a ->  c  findOf ::  < a c -> (c ->  ) -> a ->  c  findOf ::   a c -> (c ->  ) -> a ->  c  findOf ::  ( a c -> (c ->  ) -> a ->  c  A variant of 4 that has no base case and thus may only be applied K to lenses and structures such that the lens views at least one element of  the structure.   l f = H f .  l bs =     foldr1Of :: f* a c -> (c -> c -> c) -> a -> c  foldr1Of :: , a c -> (c -> c -> c) -> a -> c  foldr1Of ::  <& a c -> (c -> c -> c) -> a -> c  foldr1Of ::  % a c -> (c -> c -> c) -> a -> c  foldr1Of ::  ( a c -> (c -> c -> c) -> a -> c  A variant of Q that has no base case and thus may only be applied to lenses and strutures such < that the lens views at least one element of the structure.   l f = `t l f . = bu =     foldl1Of :: f* a c -> (c -> c -> c) -> a -> c  foldl1Of :: , a c -> (c -> c -> c) -> a -> c  foldl1Of ::  <& a c -> (c -> c -> c) -> a -> c  foldl1Of ::  % a c -> (c -> c -> c) -> a -> c  foldl1Of ::  ( a c -> (c -> c -> c) -> a -> c 6Strictly fold right over the elements of a structure.  bv =     foldrOf' :: f/ a c -> (c -> e -> e) -> e -> a -> e  foldrOf' :: 1 a c -> (c -> e -> e) -> e -> a -> e  foldrOf' ::  <+ a c -> (c -> e -> e) -> e -> a -> e  foldrOf' ::  * a c -> (c -> e -> e) -> e -> a -> e  foldrOf' ::  (% a c -> (c -> e -> e) -> e -> a -> e NFold over the elements of a structure, associating to the left, but strictly.  bw =     foldlOf' :: f/ a c -> (e -> c -> e) -> e -> a -> e  foldlOf' :: 1 a c -> (e -> c -> e) -> e -> a -> e  foldlOf' ::  <+ a c -> (e -> c -> e) -> e -> a -> e  foldlOf' ::  * a c -> (e -> c -> e) -> e -> a -> e  foldlOf' ::  (% a c -> (e -> c -> e) -> e -> a -> e IMonadic fold over the elements of a structure, associating to the right,  i.e. from right to left.  bx =     foldrMOf ::  m => f3 a c -> (c -> e -> m e) -> e -> a -> m e  foldrMOf ::  m => 5 a c -> (c -> e -> m e) -> e -> a -> m e  foldrMOf ::  m =>  </ a c -> (c -> e -> m e) -> e -> a -> m e  foldrMOf ::  m =>  . a c -> (c -> e -> m e) -> e -> a -> m e  foldrMOf ::  m =>  () a c -> (c -> e -> m e) -> e -> a -> m e HMonadic fold over the elements of a structure, associating to the left,  i.e. from left to right.  by =     foldlMOf ::  m => f3 a c -> (e -> c -> m e) -> e -> a -> m e  foldlMOf ::  m => 5 a c -> (e -> c -> m e) -> e -> a -> m e  foldlMOf ::  m =>  </ a c -> (e -> c -> m e) -> e -> a -> m e  foldlMOf ::  m =>  . a c -> (e -> c -> m e) -> e -> a -> m e  foldlMOf ::  m =>  () a c -> (e -> c -> m e) -> e -> a -> m e 3I223I Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered type SimpleTraversal =  A  can be used directly as a @ or a  (but not as a ) and provides V the ability to both read and update multiple fields, subject to some relatively weak  laws. UThese have also been known as multilenses, but they have the signature and spirit of   ::  f =>  (f a) (f b) a b8and the more evocative name suggests their application. Most of the time the  you will want to use is just , but you can also pass any   or <& as a Traversal, and composition of a  (or  or < ) with a  (or  or <)  using (.) forms a valid . The laws for a Traversal t3 follow from the laws for Traversable as stated in "#The Essence of the Iterator Pattern". 1) Idiomatic naturality:  t  = 2) Sequential composition:   (t f) . t g = ]^ . t (]_ .  f . g)vOne consequence of this requirement is that a traversal needs to leave the same number of elements as a candidate for * subsequent traversal as it started with. -3) No duplication of elements (as defined in "#The Essence of the Iterator Pattern" section 5.5), which states ] that you should incur no effect caused by visiting the same element of the container twice. AMap each element of a structure targeted by a Lens or Traversal, E evaluate these actions from left to right, and collect the results.   =   =      :: <) a b c d -> (c -> f d) -> a -> f b   :: ( a b c d -> (c -> f d) -> a -> f b   :: # a b c d -> (c -> f d) -> a -> f b   l =  ( l)   J =     =     forOf :: <# a b c d -> a -> (c -> f d) -> f b  forOf :: # a b c d -> a -> (c -> f d) -> f b  forOf :: # a b c d -> a -> (c -> f d) -> f b FEvaluate each action in the structure from left to right, and collect  the results.    K =   =     l =  l id   l = l id     :: < a b (f c) c -> a -> f b   ::  a b (f c) c -> a -> f b   ::  f =>  a b (f c) c -> a -> f b HMap each element of a structure targeted by a lens to a monadic action, E evaluate these actions from left to right, and collect the results.  L =     'mapMOf :: <) a b c d -> (c -> m d) -> a -> m b  'mapMOf :: ( a b c d -> (c -> m d) -> a -> m b  ' mapMOf ::  m => # a b c d -> (c -> m d) -> a -> m b    M =     l =  ( l)    forMOf :: <) a b c d -> a -> (c -> m d) -> m b  forMOf :: ( a b c d -> a -> (c -> m d) -> m b  forMOf ::  m => # a b c d -> a -> (c -> m d) -> m b    N =    sequenceOf l =  l id  sequenceOf l = O . l P    sequenceOf :: < a b (m c) c -> a -> m b  sequenceOf ::  a b (m c) c -> a -> m b  sequenceOf ::  m =>  a b (m c) c -> a -> m b This generalizes z{ to an arbitrary . Note: z{F handles ragged inputs more intelligently, but for non-ragged inputs:  z{ =  &transposeOf traverse [[1,2,3],[4,5,6]][[1,4],[2,5],[3,6]] Since every  is a , we can use this as a form of  monadic strength as well:   :: (b, [a] ) -> [(b, a)]  Generalizes Q to an arbitrary .  Q =    ' accumulates state from right to left.   mapAccumROf :: <9 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)  mapAccumROf :: 8 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)  mapAccumROf :: 3 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)   Generalized R to an arbitrary .  R =    ' accumulates state from left to right.   mapAccumLOf :: <9 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)  mapAccumLOf :: 8 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)  mapAccumLOf :: 3 a b c d -> (s -> c -> (s, d)) -> s -> a -> (s, b)  Permit the use of S over an arbitrary  or .  S =      scanr1Of :: <* a b c c -> (c -> c -> c) -> a -> b  scanr1Of :: ) a b c c -> (c -> c -> c) -> a -> b  scanr1Of :: $ a b c c -> (c -> c -> c) -> a -> b  Permit the use of T over an arbitrary  or .  T =     : scanr1Of :: Iso a b c c -> (c -> c -> c) -> a -> b : scanr1Of :: Lens a b c c -> (c -> c -> c) -> a -> b : scanr1Of :: Traversal a b c c -> (c -> c -> c) -> a -> b  A  to view/edit the nth element   a ,  or <. +Attempts to access beyond the range of the  will cause an error. import Control.Lens,[[1],[3,4]]^.elementOf (traverse.traverse) 13Access the nth element of a  container. +Attempts to access beyond the range of the  will cause an error.  =   %This is the traversal that just doesn't return anything  ::  f => (c -> f d) -> a -> f a                     "rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered type  i =  ( i)Every  is a valid  and a valid  C. Adjust the target of an ' returning the intermediate result, or ! adjust all of the targets of an  C and return a monoidal summary  along with the answer.  l  f = l   f/When you do not need access to the index then ()) is more liberal in what it can accept. 9If you do not need the intermediate result, you can use ( | ) or even ( }).   (<%@~) :: + i a b c d -> (i -> c -> d) -> a -> (d, b)  (<%@~) :: Monoid d =>  C+ i a b c d -> (i -> c -> d) -> a -> (d, b) Adjust the target of an & returning a supplementary result, or ! adjust all of the targets of an  C and return a monoidal summary . of the supplementary results and the answer.  () = !   (%%@~) ::  f => / i a b c d -> (i -> c -> f d) -> a -> f b  (%%@~) ::  f =>  C* i a b c d -> (i -> c -> f d) -> a -> f b ^In particular, it is often useful to think of this function as having one of these even more  restrictive type signatures   (%%@~) :: 5 i a b c d -> (i -> c -> (e, d)) -> a -> (e, b)  (%%@~) :: Monoid e =>  C0 i a b c d -> (i -> c -> (e, d)) -> a -> (e, b) Adjust the target of an & returning a supplementary result, or ! adjust all of the targets of an  C within the current state, and 9 return a monoidal summary of the supplementary results.  l  f = U (l  f)   (%%@=) ::  a m 2 i a a c d -> (i -> c -> (e, d)) -> a -> m e  (%%@=) :: ( a m, Monoid e) =>  C- i a a c d -> (i -> c -> (e, d)) -> a -> m e Adjust the target of an ' returning the intermediate result, or ! adjust all of the targets of an  C within the current state, and 8 return a monoidal summary of the intermediate results.   (<%@=) ::  a m - i a a c d -> (i -> c -> d) -> a -> m d  (<%@=) :: ( a m, Monoid e) =>  C( i a a c d -> (i -> c -> d) -> a -> m d  "rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered type  i =  ( i)#Every indexed traversal is a valid ( or  B. The # constraint is used to allow an  to be used directly as a (. The (" laws are still required to hold. Traversal with an index. NB: When you don'8t need access to the index then you can just apply your   directly as a function!     = !  ~ =  .  =     itraverseOf ::  U/ i a b c d -> (i -> c -> f d) -> a -> f b  itraverseOf :: * i a b c d -> (i -> c -> f d) -> a -> f b 3Traverse with an index (and the arguments flipped)   l a =  l a .   =  .    iforOf ::  U/ i a b c d -> a -> (i -> c -> f d) -> f b  iforOf :: * i a b c d -> a -> (i -> c -> f d) -> f b HMap each element of a structure targeted by a lens to a monadic action, Q evaluate these actions from left to right, and collect the results, with access  its position.  When you don't need access to the index mapMOf( is more liberal in what it can accept.   =  .    imapMOf ::  m =>  U/ i a b c d -> (i -> c -> m d) -> a -> m b  imapMOf ::  m => * i a b c d -> (i -> c -> m d) -> a -> m b HMap each element of a structure targeted by a lens to a monadic action, Q evaluate these actions from left to right, and collect the results, with access + its position (and the arguments flipped).     l a =  l a .    =  .     iforMOf ::  m =>  U/ i a b c d -> a -> (i -> c -> m d) -> m b  iforMOf ::  m => * i a b c d -> a -> (i -> c -> m d) -> m b  Generalizes 9 to an arbitrary  with access to the index. ' accumulates state from right to left.   l =  l .    imapAccumROf ::  U? i a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)  imapAccumROf :: : i a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)  Generalizes 9 to an arbitrary  with access to the index. ' accumulates state from left to right.   l =  l .    imapAccumLOf ::  U? i a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)  imapAccumLOf :: : i a b c d -> (i -> s -> c -> (s, d)) -> s -> a -> (s, b)  Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedThis LensK can be used to read, write or delete the value associated with a key in a V. :m + Control.Lens Data.Map.Lens(Map.fromList [("hello",12)] ^.at "hello"Just 12!at 10 .~ Just "hello" $ Map.emptyfromList [(10,"hello")] H at :: Ord k => k -> (Maybe v -> f (Maybe v)) -> Map k v -> f (Map k v) Traversal of a V indexed by the key.  +Traverse the value at a given key in a Map S traverseAt :: (Applicative f, Ord k) => k -> (v -> f v) -> Map k v -> f (Map k v) % traverseAt k = valueAt k . traverse !0Traverse the value at the minimum key in a Map. KThe key of the minimum element is available as the index of the traversal. "0Traverse the value at the maximum key in a Map. KThe key of the maximum element is available as the index of the traversal.  !" !" !" !""rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered# type # i =  ($ i)$Every $ is a valid ? The ?" laws are still required to hold. %Map with index. /When you do not need access to the index, then C( is more liberal in what it can accept.  C l = % l .    imapOf :: $) i a b c d -> (i -> c -> d) -> a -> b  imapOf ::  U+ i a b c d -> (i -> c -> d) -> a -> b  imapOf ::  C& i a b c d -> (i -> c -> d) -> a -> b &Adjust every target of an $,  U or  C  with access to the index.  (&) = %/When you do not need access to the index then (&)) is more liberal in what it can accept.  l E f = l &  f   (%@~) :: $) i a b c d -> (i -> c -> d) -> a -> b  (%@~) ::  U+ i a b c d -> (i -> c -> d) -> a -> b  (%@~) ::  C& i a b c d -> (i -> c -> d) -> a -> b '/Adjust every target in the current state of an $,  U or  C  with access to the index. /When you do not need access to the index then (S)) is more liberal in what it can accept.  l S f = l '  f   (%@=) ::  a m => $' i a a c d -> (i -> c -> d) -> m ()  (%@=) ::  a m =>  U) i a a c d -> (i -> c -> d) -> m ()  (%@=) ::  a m =>  C$ i a b c d -> (i -> c -> d) -> m () #$%&'#$%&'$%&'##$%&' RankNTypes provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered(GSometimes you need to store a path lens into a container, but at least  at this time, ImpredicativePolymorphism in GHC is somewhat lacking. *This type provides a way to, say, store a [] of polymorphic lenses. +Representable Functors. A  f is + if it is isomorphic to (x -> a) E for some x. Nearly 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 = - f is a valid choice of x for (nearly) 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 +  functor.  . f m = ,  i -> f (m k i) Usage for a + Foo:   instance  Foo where   = . //# is a valid default definition for  and W for a  + functor.  / = , .  Usage for a + Foo:    instance  Foo where   = /  ...    instance  Foo where  W = /  ... 00$ is a valid default definition for (X) for a +  functor.  0 mf ma = ,  i -> mf k i  ma k i Usage for a + Foo:   instance  Foo where   = /  (X) = 0 11+ is a valid default default definition for '(>>=)' for a  representable functor.  1 m f = ,  i -> f (m k i) k i Usage for a + Foo:   instance  Foo where  W = /  (Y) = 1 2A default definition for  for a +   2 wf = ,  i ->  (k i) wf Usage for a + Foo:   instance  Foo where   = 2 3A + - has a fixed shape. This fills each position  in it with a ( 4 A version of ,5 that is an isomorphism. Predicativity requires that  we wrap the - as a Key , however. 5 Map over a + functor with access to the  for the  current position 5 f m = ,  i -> f i (m k i)6 Traverse a +) functor with access to the current path 7 Traverse a +) functor with access to the current path  as a , discarding the result 8 Traverse a +) functor with access to the current path  and a  (and the arguments flipped) 9L over a +) functor with access to the current path  as a  :L over a +) functor with access to the current path  as a , discarding the result ;L over a +) functor with access to the current path  as a  (with the arguments flipped) < Fold over a +) functor with access to the current path  as a  , yielding a  = Fold over a +) functor with access to the current path  as a . ZNB: The 5@ requirement on this instance is a consequence of the choice of  as a -, it isn't fundamental. ()*+,-./0123456789:;<=Z[()*+,-./0123456789:;<=+,-./012()*345<=6789:;()*+,-./0123456789:;<=Z[portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered>This 4 can be used to read, write or delete a member of a \ :m + Data.Set.Lens Control.Lens,contains 3 .~ False $ Set.fromList [1,2,3,4]fromList [1,2,4] B contains :: Ord k => k -> (Bool -> f Bool) -> Set k -> f (Set k) ?This ?% can be used to change the type of a \ by mapping  the elements to new values. Sadly, you can't create a valid  Traversal for a \, but you can  manipulate it by reading using folded and reindexing it via setmap. :m + Data.Set.Lens Control.Lens*adjust setmapped (+1) (fromList [1,2,3,4])fromList [2,3,4,5]@Construct a set from a f, Fold,  Traversal,  or Iso. :m + Data.Set.Lens Control.Lens5setOf (folded._2) [("hello",1),("world",2),("!!!",3)]fromList [1,2,3]   setOf :: f a c -> a -> \ c  setOf :: E c => Fold a c -> a -> \ c  setOf ::  Iso a c -> a -> \ c  setOf ::   a c -> a -> \ c  setOf :: E c =>   Traversal a c -> a -> \ c >?@>?@>?@>?@TemplateHaskell experimentalEdward Kmett <ekmett@gmail.com> TrustworthyA Provides substitution for types BPerform substitution for types CHProvides for the extraction of free type variables, and alpha renaming. D4When performing substitution into this traversal you're not allowed 8 to substitute in a name that is bound internally or you' ll violate  the . laws, when in doubt generate your names with ]. EHas a ^ FExtract (or modify) the ^ of something G Traverse free type variables H'Substitute using a map of names in for free type variables ABCDEFGH_`abcdefghiABCDEFGHEFCDABGHABCDEFGH_`abcdefghiTemplateHaskell experimentalEdward Kmett <ekmett@gmail.com> TrustworthyI+This configuration describes the options we'+ll be using to make isomorphisms or lenses KFlags for lens construction TOnly Generate valid   lenses U(Handle singleton constructors specially V#Use Iso for singleton constructors W@Expect a single constructor, single field newtype or data type. X6Create the class if the constructor is simple and the ] rule matches Y9Create the instance if the constructor is simple and the ] rule matches Z Die if the ] fails to match [RLens to access the convention for naming top level isomorphisms in our lens rules =Defaults to lowercasing the first letter of the constructor. \BLens to access the convention for naming fields in our lens rules ODefaults to stripping the _ off of the field name and lowercasing the name and  rejecting the field if it doesn't start with an '_'. ]wRetrieve options such as the name of the class and method to put in it to build a class around monomorphic data types. ^wRetrieve options such as the name of the class and method to put in it to build a class around monomorphic data types. _Default lens rules `)Build lenses with a custom configuration a3Build lenses with a sensible default configuration ' makeLenses = makeLensesWith lensRules b7Make a top level isomorphism injecting _into_ the type dThe supplied name is required to be for a type with a single constructor that has a single argument # makeIso = makeLensesWith isoRules c1Rules for making an isomorphism from a data type dMake ' classy lenses' for a type ) makeClassy = makeLensesWith classyRules e6Rules for making lenses that precompose another lens. f/Derive lenses, specifying explicit pairings of (fieldName, lensName). Example usage: < makeLensesFor [("_foo", "fooLens"), ("bar", "lbar")] ''Foo gpRules for making fairly simple lenses, ignoring the special cases for isomorphisms, and not making any classes. h/Derive lenses, specifying explicit pairings of (fieldName, lensName)  using a wrapper class. Example usage: K makeClassyFor "HasFoo" "foo" [("_foo", "fooLens"), ("bar", "lbar")] ''Foo IJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh IJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh IJ[\]^KSRQPONMLTUVWXYZdhbaf`gec_IJKSRQPONMLTUVWXYZ[\]^_`abcdefgh Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered< !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~     #$%&'()*+,-./0123456789:;<=IJKLMNOPQRSTUVWXYZ[\]^_`abcdefghControl.Exception provisionalEdward Kmett <ekmett@gmail.com> Safe-InferediTraverse the strongly typed j contained in k) where the type of your function matches  the desired j.   traverseException :: ( f, j a, j b) $ => (a -> f b) -> k -> f k iiiiLiberalTypeSynonyms experimentalEdward Kmett <ekmett@gmail.com> Safe-InferedjBitwise l the target(s) of a -valued  or ? _2 |~ 6 $ ("hello",3) ("hello",7)kBitwise m the target(s) of a -valued  or ? _2 &~ 7 $ ("hello",254) ("hello",6)lModify the target(s) of a  , ? or  by computing its bitwise m with another value. mModify the target(s) of a  , ? or  by computing its bitwise l with another value. nFThis lens can be used to access the value of the nth bit in a number. n n is only a legal  into b if 0 <= n < n (o :: b)  16^.bitAt 4True 15^.bitAt 4Falseo*Traverse over all bits in a numeric type. ,The bit position is available as the index. import Data.Word"toListOf traverseBits (5 :: Word8)/[True,False,True,False,False,False,False,False]If you supply this an p, the result will  be an infinite $ that can be productively consumed. jklmnojklmnojkmlnojklmno Rank2Types experimentalEdward Kmett <ekmett@gmail.com> Safe-Inferedp Access the q of a r number ? real :: Functor f => (a -> f a) -> Complex a -> f (Complex a) q Access the  imaginaryPart of a r number D imaginary :: Functor f => (a -> f a) -> Complex a -> f (Complex a) rThis isn't quite a legal lens. Notably the  h l (D l b a) = blaw is violated when you set a s value with 0 t and non-zero u  as the u information is lost. So don' t do that! )Otherwise, this is a perfectly cromulent . s0Traverse both the real and imaginary parts of a r number. N traverseComplex :: Applicative f => (a -> f b) -> Complex a -> f (Complex b) pqrspqrspqrspqrsportable provisionalEdward Kmett <ekmett@gmail.com> Safe-Inferedt(Traverse the typed value contained in a v7 where the type required by your function matches that  of the contents of the v. b traverseDynamic :: (Applicative f, Typeable a, Typeable b) => (a -> f b) -> Dynamic -> f Dynamic ttttportable provisionalEdward Kmett <ekmett@gmail.com> Safe-Inferedu;A traversal for tweaking the left-hand value in an Either: M traverseLeft :: Applicative f => (a -> f b) -> Either a c -> f (Either b c) v,traverse the right-hand value in an Either:   traverseRight = traverse Unfortunately the instance for 'Traversable (Either c)' is still missing  from base, so this can' t just be  N traverseRight :: Applicative f => (a -> f b) -> Either c a -> f (Either c a) uvuvuvuvportable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered w,A lens reading and writing to the head of a  non-empty list [1,2,3]^._head1x,A lens reading and writing to the tail of a  non-empty list _tail .~ [3,4,5] $ [1,2] [1,3,4,5]y4A lens reading and writing to the last element of a  non-empty list  [1,2]^._last2z=A lens reading and replacing all but the a last element of a  non-empty list [1,2,3,4]^._init[1,2,3]{CObtain a version of the list with the supplied value interspersed. "abcde"^.interspersed ',' "a,b,c,d,e" ' xs^.interspersed a = intersperse a xs |BObtain a version of the list with the supplied value intercalated }QIndexed traversal of a list. The position in the list is available as the index. ~<The traversal for reading and writing to the head of a list MThe position of the head in the original list (0) is available as the index. traverseHead +~ 1 $ [1,2,3][2,2,3] = traverseHead :: Applicative f => (a -> f a) -> [a] -> f [a] *Traversal for editing the tail of a list. The position of each element in the original list is available as the index. traverseTail +~ 1 $ [1,2,3][1,3,4] = traverseTail :: Applicative f => (a -> f a) -> [a] -> f [a] %Traverse the last element in a list. QThe position of the last element in the original list is available as the index. traverseLast +~ 1 $ [1,2,3][1,2,4] = traverseLast :: Applicative f => (a -> f a) -> [a] -> f [a] ,Traverse all but the last element of a list 8The position of each element is available as the index. traverseInit +~ 1 $ [1,2,3][2,3,3] = traverseInit :: Applicative f => (a -> f a) -> [a] -> f [a] wxyz{|}~ wxyz{|}~ wxyz{|}~ wxyz{|}~portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered4Traverse both parts of a tuple with matching types. This provides a ) that checks a predicate on a key before ( allowing you to traverse into a value.  Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedThis L can be used to read, write or delete the value associated with a key in an w. fromList [(1,"hello")] ^.at 1 Just "hello"#at 1 .~ Just "hello" $ IntMap.emptyfromList [(1,"hello")] C at :: Int -> (Maybe v -> f (Maybe v)) -> IntMap v -> f (IntMap v) Traversal of an w indexed by the key. /Traverse the value at a given key in an IntMap N traverseAt :: Applicative f => Int -> (v -> f v) -> IntMap v -> f (IntMap v)  traverseAt k = at k . traverse /Traverse the value at the minimum key in a Map :The key of the minimum element is available as the index. /Traverse the value at the maximum key in a Map portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedThis 5 can be used to read, write or delete a member of an x  0 ghci> contains 3 +~ False $ fromList [1,2,3,4]  fromList [1,2,4]  contains ::  f =>  -> ( -> f ) -> x -> f x IntSet isn't Foldable, but this ) can be used to access the members of an x. &sumOf members $ setOf folded [1,2,3,4]10This ?* can be used to change the contents of an x by mapping  the elements to new values. Sadly, you can't create a valid  for a Set, because the number of B elements might change but you can manipulate it by reading using  and  reindexing it via setmap. *adjust setmapped (+1) (fromList [1,2,3,4])fromList [2,3,4,5] Construct an x from a f, , ,  or +. ":m + Data.IntSet.Lens Control.Lens5setOf (folded._2) [("hello",1),("world",2),("!!!",3)]fromList [1,2,3]   setOf :: f a  -> a -> x  setOf ::  a  -> a -> x  setOf ::  + a  -> a -> x  setOf ::   a  -> a -> x  setOf ::   a  -> a -> x portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered A  that can access the nth element of a y. =Note: This is only a legal lens if there is such an element! A y is isomorphic to a z  viewl m = m^.viewL A y is isomorphic to a {  viewr m = m^.viewR Traverse the head of a y Traverse the tail of a y Traverse the last element of a y 'Traverse all but the last element of a y Traverse the first n elements of a y Traverse all but the first n elements of a y 'Travere all the elements numbered from i to j of a y    MTPCs provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedA  that focuses on the root of a |. A , of the direct descendants of the root of a | 1 indexed by its position in the list of children &MPTCs, Rank2Types, LiberalTypeSynonyms provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedAccess an element of an array. <Note: The indexed element is assumed to exist in the target }.  arr ~ i = arr k  i arr  [(i,e)] =  i F e  arr:ix 2 .~ 9 $ (listArray (1,5) [4,5,6,7,8] :: Array Int Int)+array (1,5) [(1,4),(2,9),(3,6),(4,7),(5,8)](This setter can be used to derive a new } from an old array by E applying a function to each of the indices to look it up in the old }.  This is a  contravariant ?.   = B .   = A .  B ( b) f arr ~ i = arr ~ f i  (B ( b) f arr) = bAn  of the elements of an } , using the 5 index into the array as the index of the traversal.  = B  portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered (or ) a list of bytes into a    x = x k   x = x k 1 Traverse each  in a    = 1  & }   ( 0x80) ::  ->  (or ) a list of characters into a  When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   x = x k   x = x k 1 #Traverse the individual bytes in a  as characters. When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   = 1 packed .    ( 'c') ::  -> !portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered (or ) a list of bytes into a    x = x k   x = x k 1 #Traverse the individual bytes in a    = 1  . }   ( 0x80) ::  ->  (or ) a list of characters into a  When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   x = x k   x = x k 1 #Traverse the individual bytes in a  as characters. When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   = 1  & }   ( 'c') ::  -> "portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedPack (or unpack) .  pack x = x^.packed  unpack x = x^.from packed >Traverse the individual characters in a either strict or lazy . $ anyOf text (=='c') :: Text -> Bool #portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedPack (or unpack) .  pack x = x^.packed  unpack x = x^.from packed (Traverse the individual characters in a . $ anyOf text (=='c') :: Text -> Bool $portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferedEvaluate the targets of a  or  into a data structure " according to the given strategy.     =  evalTraversal  =    evalTraversal =     evalTraversal ::   a b ->  b ->  a  evalTraversal ::   a b ->  b ->  a  evalTraversal :: (b ->  b) -> a ->  a) ->  b ->  a Evaluate the targets of a  or  according into a % data structure according to a given  in parallel.   =  parTraversal    parTraversal ::   a b ->  b ->  a  parTraversal ::   a b ->  b ->  a  parTraversal :: ((b ->  b) -> a ->  a) ->  b ->  a  Transform a , , f, ? or  to < first evaluates its argument according to a given strategy before proceeding.      ::  t =>  a ->  [a]  Transform a , , f, ? or  to 5 evaluate its argument according to a given strategy in parallel with evaluating.      ::  t =>  a ->  [a] %portable provisionalEdward Kmett <ekmett@gmail.com> Safe-Infered$Evaluate the elements targeted by a , , +,  f or " according to the given strategy.  seqFoldable = seqOf folded &GHC experimentalEdward Kmett <ekmett@gmail.com> Safe-InferedUsed to traverse  data by . ;Convert from the data type to its representation (or back) '"hello"^.generic.from generic :: String"hello";Convert from the data type to its representation (or back) A   that visits every occurence  of something  anywhere in a container. ?allOf every (=="Hello") (1::Int,2::Double,(),"Hello",["Hello"])True7mapMOf_ every putStrLn ("hello",[(2 :: Int, "world!")])helloworld!  9V9;<?@}\ B                                  ! " # 5 $ % & ' ( ) 6 3 * + , - . / 4 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E A F G H I J K L M > N O D P G H T Q R I J S T , K U L M V W X Y Z [ \ ] ^ _ ` ) * a b O c t P Q R Sd(~efghi/'j E U k l m n F C o p q r s tuvwxyz{||}~~WoZ=uwxyuZ    !!!!""##$$$$%&&&&       !"#$%&'() *!+,-./0123456789:;<=>?@A@BCDEFG H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u vbwxyxzx{x|}~bbb b5bbbbxx@@bgxxb@bxs 99999  99xx!"G XXYXXX788&&&&&&lens-2.0Control.Lens.TraversalControl.Lens.InternalControl.Lens.IndexedControl.Lens.IsoControl.Lens.SetterControl.Lens.GetterControl.Lens.ActionControl.Lens.IndexedGetterControl.Lens.IndexedFoldControl.Lens.TypeControl.Lens.FoldControl.Lens.IndexedLensControl.Lens.IndexedTraversal Data.Map.LensControl.Lens.IndexedSetterControl.Lens.Representable Data.Set.LensLanguage.Haskell.TH.LensControl.Lens.THControl.Exception.LensData.Bits.LensData.Complex.LensData.Dynamic.LensData.Either.LensData.List.LensData.Pair.LensData.IntMap.LensData.IntSet.LensData.Sequence.LensData.Tree.LensData.Array.LensData.ByteString.LensData.ByteString.Lazy.LensData.Text.LensData.Text.Lazy.Lens Control.Parallel.Strategies.LensControl.Seq.LensGHC.Generics.Lenselement Traversal maximumOf minimumOfmapM_ traverseOf_Control.Monad.Trans.State.LazyState elementOf elementsOftraverseElementtraverseElementsOfLenscloneFocusSimpleData.Text.InternalTextData.Traversable fmapDefaulttraverseIsoboth backwardsSettableSetterFold IndexedFoldIndexedTraversal foldMapOfSimpleIndexedLensSimpleIndexedTraversalfoldrOffoldlOfanyOfallOfforOf_mapMOf_forMOf_ concatMapOf_findOffoldrOf'foldlOf'foldrMOffoldlMOftoListOf IndexedLens Traversable imaginary Data.ComplexComplex traverseHeadControl.Lens.LensGettingData.Functor.Compose getComposeComposePreludeunfoldr Data.FoldablefoldMapfoldfoldrfoldltoListandoranyallproductsum traverse_ traverseLeftforM_ sequence_ maximumByfoldr1foldl1Offoldl1foldr'foldl'foldrMfoldlM Data.List transpose%@~%~ traverseOfforOfmapMOfforMOf mapAccumR mapAccumROf mapAccumL mapAccumLOfData.Distributive distribute Distributive Control.LensData.ByteStringpackunpackData.ByteString.Char8Data.ByteString.LazyData.ByteString.Lazy.Char8base ElementOf getElementOfElementOfResultNotFoundFound SearchingMaxNoMaxMinNoMin Sequenced getSequenced Traversed getTraversed AppliedStaterunAppliedState IndexedStoreFocusing unfocusinggetMingetMaxIndex withIndex IndexableIndexedindex<..>reindex<.>icompose SimpleIso Isomorphism Isomorphic isomorphicisomapfromviaisosisoidentity_constMutator runMutator untainted SimpleSetting SimpleSetterSettingmappedsetsadjustmapOfset.~<.~+~*~-~//~^~^^~**~||~&&~<>~.=%=+=-=*=//=^=^^=**=&&=||=<>=<~<.=Accessor runAccessorGettablecoerceGettertoviewviews^$^.queryqueriesuseusesActingEffect getEffect Effective effective MonadicFoldAction ineffectiveperform^!actactsliftActIndexedGetting IndexedGetter ifoldMapOfifoldrOfifoldlOfianyOfiallOf itraverseOf_iforOf_imapMOf_iforMOf_ iconcatMapOfifindOf ifoldrOf' ifoldlOf' ifoldrMOf ifoldlMOf itoListOf ifiltered itakingWhileidroppingWhileField9_9Field8_8Field7_7Field6_6Field5_5Field4_4Field3_3Field2_2Field1_1SimpleOverloaded Overloadedfocusfocus_setFocusLensLikeSimpleLensLike SimpleLenslens%%~%%=resultAtmerged bothLenses<%~<+~<-~<*~~<%=<+=<-=<*==foldingfoldedrepeated replicatedcycledunfoldediteratedfiltered takingWhile droppingWhilefoldOfandOforOf productOfsumOf sequenceAOf_ sequenceOf_asumOfmsumOfelemOf notElemOf concatMapOfconcatOflengthOfheadOflastOfnullOf maximumByOf minimumByOffoldr1OfSimpleTraversal sequenceAOf sequenceOf transposeOfscanr1Ofscanl1OftraverseNothing<%@~%%@~%%@=<%@= itraverseOfiforOfimapMOfiforMOf imapAccumROf imapAccumLOfat traverseMap traverseAt traverseAtMin traverseAtMaxSimpleIndexedSetter IndexedSetterimapOf%@=Pathwalk RepresentablerepRepfmapReppureRepapRepbindRep distributeReppaths tabulated mapWithReptraverseWithReptraverseWithRep_ forWithRep mapMWithRep mapMWithRep_ forMWithRepfoldMapWithRep foldrWithRepcontains setmappedsetOf SubstType substType HasTypeVars typeVarsExHasNamenametypeVars substTypeVars LensRulesLensFlag ClassRequiredCreateInstance CreateClassSingletonRequiredHandleSingletons SingletonIsoSingletonAndField SimpleLenses simpleLenseshandleSingletons singletonIsosingletonRequired createClasscreateInstance classRequiredlensIso lensField lensClass lensFlags defaultRulesmakeLensesWith makeLensesmakeIsoisoRules makeClassy classyRules makeLensesFor lensRules makeClassyFortraverseException|~&~&=|=bitAt traverseBitsrealpolarizetraverseComplextraverseDynamic traverseRight_head_tail_last_init interspersed intercalated traverseList traverseTail traverseLast traverseInitvaluetraverseIntMapmembersviewLviewR traverseTo traverseFrom traverseSlicerootchildrenixixmapped traverseArray packedBytesbytes packedCharscharspackedtextevalOfparOfafter meanwhileseqOf GTraversalgenericgeneric1everyghc-prim GHC.TypesIntGHC.BaseFunctor$fApplicativeElementOf$fFunctorElementOf$fFunctorElementOfResult $fMonoidMax $fMonoidMin$fMonoidSequenced$fMonoidTraversed$fApplicativeAppliedState$fFunctorAppliedState$fFunctorIndexedStore$fApplicativeFocusing$fFunctorFocusing$fIndexediIndex$fIndexedi(->)Control.Category.idCategorytransformers-0.3.0.0Data.Functor.IdentityIdentityControl.ApplicativeConst$fIsomorphicIsomorphism$fCategoryIsomorphism$fIsomorphic(->)Charpurefmap<$$GHC.NumNumGHC.Real FractionalIntegral GHC.FloatFloating GHC.Classes||Bool&& Data.MonoidmappendMonoid mtl-2.1.2Control.Monad.State.Class MonadState$fSettableBackwards$fSettableIdentity$fSettableMutator$fApplicativeMutator$fFunctorMutator$fSettableCompose ApplicativeControl.Monad.Reader.Class MonadReader$fGettableElementOf$fApplicativeAccessor$fGettableAccessor$fFunctorAccessor$fGettableCompose$fGettableBackwards$fGettableConstMonad Control.Monadjoin$fEffectivemrEffect$fGettableEffect$fApplicativeEffect$fMonoidEffect$fFunctorEffect$fEffectivemDualBackwards$fEffectiveIdentityrAccessorconstflip Data.MaybeNothingMaybemap Data.Tuplefst Control.Monad.Trans.State.Strictstate$fField9(,,,,,,,,)(,,,,,,,,)ii'$fField8(,,,,,,,,)(,,,,,,,,)hh'$fField8(,,,,,,,)(,,,,,,,)hh'$fField7(,,,,,,,,)(,,,,,,,,)gg'$fField7(,,,,,,,)(,,,,,,,)gg'$fField7(,,,,,,)(,,,,,,)gg'$fField6(,,,,,,,,)(,,,,,,,,)ff'$fField6(,,,,,,,)(,,,,,,,)ff'$fField6(,,,,,,)(,,,,,,)ff'$fField6(,,,,,)(,,,,,)ff'$fField5(,,,,,,,,)(,,,,,,,,)ee'$fField5(,,,,,,,)(,,,,,,,)ee'$fField5(,,,,,,)(,,,,,,)ee'$fField5(,,,,,)(,,,,,)ee'$fField5(,,,,)(,,,,)ee'$fField4(,,,,,,,,)(,,,,,,,,)dd'$fField4(,,,,,,,)(,,,,,,,)dd'$fField4(,,,,,,)(,,,,,,)dd'$fField4(,,,,,)(,,,,,)dd'$fField4(,,,,)(,,,,)dd'$fField4(,,,)(,,,)dd'$fField3(,,,,,,,,)(,,,,,,,,)cc'$fField3(,,,,,,,)(,,,,,,,)cc'$fField3(,,,,,,)(,,,,,,)cc'$fField3(,,,,,)(,,,,,)cc'$fField3(,,,,)(,,,,)cc'$fField3(,,,)(,,,)cc'$fField3(,,)(,,)cc'$fField2(,,,,,,,,)(,,,,,,,,)bb'$fField2(,,,,,,,)(,,,,,,,)bb'$fField2(,,,,,,)(,,,,,,)bb'$fField2(,,,,,)(,,,,,)bb'$fField2(,,,,)(,,,,)bb'$fField2(,,,)(,,,)bb'$fField2(,,)(,,)bb'$fField2(,)(,)bb'$fField1(,,,,,,,,)(,,,,,,,,)aa'$fField1(,,,,,,,)(,,,,,,,)aa'$fField1(,,,,,,)(,,,,,,)aa'$fField1(,,,,,)(,,,,,)aa'$fField1(,,,,)(,,,,)aa'$fField1(,,,)(,,,)aa'$fField1(,,)(,,)aa'$fField1(,)(,)aa'$fFocusReaderT $fFocusStateT$fFocusStateT0FoldableGHC.Listrepeat replicate takeWhile dropWhile Data.EitherEitherfor_ sequenceA_asum Alternativemsum MonadPluselemEqnotElem concatMapconcatlengthheadJust listToMaybelastTrueFalsenullmaximum fromMaybeGHC.ErrerrorOrdminimumOrdering $fMonoidGAfor sequenceAmapMforMsequence unwrapMonad WrapMonadscanr1scanl1containers-0.4.2.1Data.MapMapreturn<*>>>=$fRepresentable(->)$fRepresentableIdentityData.SetSettemplate-haskellLanguage.Haskell.TH.SyntaxnewNameName$fSubstTypePred $fSubstType[]$fSubstTypeType$fHasTypeVars[]$fHasTypeVarsPred$fHasTypeVarsType$fHasTypeVarsName$fHasTypeVarsTyVarBndr $fHasNameCon $fHasNameName$fHasNameTyVarBndr GHC.Exception Exception SomeException Data.Bits.|..&.bitSize undefined integer-gmpGHC.Integer.TypeIntegerrealPartpolar magnitudephase Data.DynamicDynamic Data.IntMapIntMap Data.IntSetIntSet Data.SequenceSeqViewLViewR Data.TreeTree array-0.4.0.0Data.Array.BaseIArray!//ixmapboundsamapbytestring-0.9.2.1Data.ByteString.Internal ByteStringGHC.WordWord8==Data.ByteString.Lazy.Internal text-0.11.2.2Data.Text.Lazy.Internalparallel-3.2.0.3Control.Parallel.StrategiesevalTraversableStrategyEvalparTraversablerdeepseq GHC.GenericsGenericData.Typeable.InternalTypeable$fGTraversal:.:$fGTraversalM1$fGTraversal:+:$fGTraversal:*:$fGTraversalU1$fGTraversalK1