N *      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                  ! " # $ % & ' ( ) * + , - ./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !!!!!!!!!!""""####$$$$$%%%%%%%&'''((((())))))))))))))))**********++,,---..//0000000000011111 1 1 1 1 1111122223334444444 4!4"4#4$4%5&5'5(5)69 Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy GThis class permits overloading of function application for things that ( also admit a notion of a key or index. Build a function from an Indexed function 'Used to provide overloading of prisms. An instance of  is a *2 with a canonical mapping to it from the category 3 of embedding-projection pairs over Haskell types. Build a 7. + t a is used instead of , a to permit the types of s and t to differ. 7Used to provide overloading of isomorphism application An instance of  is a *) with a canonical mapping to it from the . category of isomorphisms over Haskell types. <Build a simple isomorphism from a pair of inverse functions   view ( f g) "a f  view (from ( f g)) "a g  set ( f g) h "a g - h - f  set (from ( f g)) h "a f - h - g  Anything  must be isomorphic to the . /. An   /K ignores its argument and is isomorphic to a monad wrapped around a value. 9That said, the monad is possibly rather unrelated to any 0 structure.  Generalizing 1 so we can apply simple 0 > transformations to it and so we can get nicer error messages A  /4 ignores its argument, which it carries solely as a  phantom type parameter. To ensure this, an instance of  is required to satisfy:  2 = 3 f =  Which is equivalent to making a  f an " anyvariant" functor. #Replace the phantom type argument. The mempty equivalent for a  0 /. 4 8 5so you can pass our a 9, into combinators from other lens libraries  678945:;<=     678945:;<= Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy#YA function with access to a index. This constructor may be useful when you need to store  a  in a container to avoid ImpredicativeTypes. 3Reify all of the information given to you by being . IThis data type is used to capture all of the information provided by the   -- class, so you can turn a  around into a Getter or + otherwise muck around with its internals. %If you see a function that expects a  or APrism, it is probably  just expecting a . Extract b from the type a -> f b Extract a from the type a -> f b  is like /), except that it provides a questionable  instance @ To protect this instance it relies on the soundness of another  type, and usage conventions. @For example. This lets us write a suitably polymorphic and lazy : , but there  must be a better way!   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. #A > for a  0. &Used instead of 1 to report  No instance of (; &)#when the user attempts to misuse a 9 as a  <., rather than a monolithic unification error. )OWrap a monadic effect with a phantom type argument. Used when magnifying RWST. ,4Wrap a monadic effect with a phantom type argument. /This is used to characterize a =. Ta.k.a. indexed Cartesian store comonad, indexed Kleene store comonad, or an indexed FunList.  *http://twanvl.nl/blog/haskell/non-regular1 / a b t is isomorphic to 9data Bazaar a b t = Buy t | Trade (Bazaar a b (b -> t)) a,  and to exists s. (s, = s t a b). A / is like a =2 that has already been applied to some structure. Where a 2 a b t holds an a and a function from b to  t, a / a b t holds N as and a function from N  bs to t. Mnemonically, a /0 holds many stores and you can easily add more. This is a final encoding of /. 20The indexed store can be used to characterize a  >  and is used by  ? 2 a b t is isomorphic to  Znewtype Context a b t = Context { runContext :: forall f. Functor f => (a -> f b) -> f t },  and to exists s. (s,  > s t a b). A 2 is like a  >4 that has already been applied to a some structure. 4 Used for  @ 7 Used for  A :Used internally by B and the like. =Used internally by C and the like. @Applicative composition of DE ? with a /, used  by F CUsed by  G to  H into IJ FMake a monoid out of + for error handling IUsed by  G to  H into IJ LMake a monoid out of , for error handling OUsed by  G to  H into KL or MN RUsed by  G to  H into OP. UUsed by  G to  H into QR XUsed by  G to  H into ST [Obtain the minimum. \Obtain the maximum ]AGiven an action to run for each matched pair, traverse a bazaar. ] :: = (/ a b t) t a b^/ is an indexed @. _ A trivial /. `Extract from a . ` = A a is an indexed @. b A trivial . BCUsing an equality witness to avoid potential overlapping instances  and aid dispatch. C !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abBDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxQ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abQLMN#$%,-.)*+&'(FGH=>?:;<XYZUVWRSTOPQIJKCDE !"/01]^_`ab23465\798[@ABYC !"#$%&'()*+,-./0123465798:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abBDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxURank2Types, KindSignatures provisionalEdward Kmett <ekmett@gmail.com> Trustworthy6yz{|}~6yz{|}~6yz{|}~"rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Safe-Inferredc Compose an ' function with a non-indexed function. Mnemonically, the <- points to the indexing we want to preserve. d'Compose a non-indexed function with an  function. Mnemonically, the >- points to the indexing we want to preserve. eRemap the index. fComposition of  functions Mnemonically, the < and >: points to the fact that we want to preserve the indices. gComposition of ? functions with a user supplied function for combining indices h Transform an  Traversal into an V or  a Fold into an W, etc.   h :: = s t a b -> V ? s t a b  h :: 7 s t a b -> V ? s t a b  h ::  > s t a b -> X ? s t a b  h :: Y s t a b -> X ? s t a b  h ::  Z s t -> W ? s t  h :: < s t -> [ ? s t a b cdefgh cdefgh fcdgehcdefghrank 2 types, MPTCs experimentalEdward Kmett <ekmett@gmail.com> Safe-InferrediUseful for storage. lUsed to consume an W. mEvery m is a valid W and Getter. nView the index and value of an m) into the current environment as a pair. When applied to an  IndexedFoldB the result will most likely be a nonsensical monoidal summary of f the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted. o-View a function of the index and value of an m into the current environment When applied to an  IndexedFoldC the result will be a monoidal summary instead of a single answer. o "a \pUse the index and value of an m# into the current state as a pair. When applied to an  IndexedFoldB the result will most likely be a nonsensical monoidal summary of f the indices tupled with a monoidal summary of the values and probably not whatever it is you wanted. q,Use a function of the index and value of an m into the current state. When applied to an  IndexedFoldC the result will be a monoidal summary instead of a single answer. ijklmnopq ijklmnopq mlijknopqijklmnopqMTPCs, FDs, Rank2 experimentalEdward Kmett <ekmett@gmail.com> Safe-Inferred rUsed to evaluate an t. sA s is a Fold enriched with access to a  for side-effects. Every Fold can be used as a s(, that simply ignores the access to the . You can compose a s with another s using ( ) from the Prelude. tAn t is a Getter enriched with access to a  for side-effects. Every Getter can be used as an t You can compose an t with another t using ( ) from the Prelude. u Perform an t. u "a A (w)v Perform an t and modify the result. w Perform an t &["hello","world"]^!folded.act putStrLnhelloworldx Construct an t from a monadic side-effect 2["hello","world"]^!folded.act (\x -> [x,x ++ "!"])9["helloworld","helloworld!","hello!world","hello!world!"]yA self-running t, analogous to ]^.  y "a x (1,"hello")^!_2.acts.to succ"ifmmp"zApply a  transformer to an t. rstuvwxyz rstuvwxyz txyuvzwsr rstuvwxyz Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-Inferred-{ type { =  _ ||:Reify a setter so it can be stored safely in a container. 0This is a useful alias for use when consuming a . 1Most user code will never have to use this type. type  m =  _ A Simple Setter is just a  that doesn't change the types. IThese are particularly common when talking about monomorphic containers. e.g.   Data.Text.map ::  `a  type  =  _  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   rather than bc, we get nicer error messages.  The only  >-like law that can apply to a  l is that   l y ( l x a) "a  l y aYou can't view a 3 in general, so the other two laws are irrelevant.  However, two / laws apply to a :     l  "a    l f   l g "a  l (f  g) "These an be stated more directly:    l pure "a pure  l f .   . l g "a l (f .   . g) You can compose a  with a  > or a = using () from the Prelude ! and the result is always only a  and nothing more. over traverse f [a,b,c,d][f a,f b,f c,f d]over _1 f (a,b)(f a,b)"over (traverse._1) f [(a,b),(c,d)][(f a,b),(f c,d)]over both f (a,b) (f a,f b)$over (traverse.both) f [(a,b),(c,d)][(f a,f b),(f c,f d)];This setter can be used to map over all of the values in a /.    3 "a    de "a  df  (<$) "a   over mapped f [a,b,c] [f a,f b,f c]over mapped (+1) [1,2,3][2,3,4]set mapped x [a,b,c][x,x,x] [[a,b],[c]] & mapped.mapped +~ x[[a + x,b + x],[c + x]]=over (mapped._2) length [("hello","world"),("leaders","!!!")][("hello",5),("leaders",3)]9This setter can be used to modify all of the values in a . ,You sometimes have to use this, rather than , because due to  temporary insanity / is not a superclass of .     "a   over lifted f [a,b,c] [f a,f b,f c]set lifted b (Just a)Just b)Build a Setter from a map-like function. Your supplied function f is required to satisfy:    f  "a   f g  f h "a f (g  h) Equational reasoning:       "a      "a  Another way to view  is that it takes a "semantic editor combinator"  and transforms it into a . Modify the target of a  > or all the targets of a  or =  with a function.    3 "a    de "a  df     "a      "a  Given any valid  l , you can also rely on the law:   l f .  l g =  l (f . g)e.g. Dover mapped f (over mapped g [a,b,c]) == over mapped (f . g) [a,b,c]TrueAnother way to view  is to say that it transforms a  into a  "semantic editor combinator". over mapped f (Just a) Just (f a)over mapped (*10) [1,2,3] [10,20,30]over _1 f (a,b)(f a,b)over _1 show (10,20) ("10",20)  ::  s t a b -> (a -> b) -> s -> t is a deprecated alias for . Replace the target of a  > or all of the targets of a   or = with a constant value.  (<$) "a  set _2 "hello" (1,()) (1,"hello")set mapped () [1,2,3,4] [(),(),(),()]Note: Attempting to  a Fold or Getter# will fail at compile time with an  relatively nice error message.    ::  s t a b -> b -> s -> t   :: Y s t a b -> b -> s -> t   ::  > s t a b -> b -> s -> t   :: = s t a b -> b -> s -> t Replace the target of a  > or all of the targets of a  _   or  _ =3 with a constant value, without changing its type. %This is a type restricted version of *, which retains the type of the original. set' mapped x [a,b,c,d] [x,x,x,x]set' _2 "hello" (1,"world") (1,"hello")set' mapped 0 [1,2,3,4] [0,0,0,0]Note: Attempting to adjust  a Fold or Getter# will fail at compile time with an  relatively nice error message.    ::  _  s a -> a -> s -> s   ::  _ Y s a -> a -> s -> s   ::  _  > s a -> a -> s -> s   ::  _ = s a -> a -> s -> s Modifies the target of a  > or all of the targets of a  or  = with a user supplied function. This is an infix version of     3 f "a   f  de f "a traverse  f (a,b,c) & _3 %~ f (a,b,f c)(a,b) & both %~ f (f a,f b)_2 %~ length $ (1,"hello")(1,5)traverse %~ f $ [a,b,c] [f a,f b,f c]traverse %~ even $ [1,2,3][False,True,False]9traverse.traverse %~ length $ [["hello","world"],["!!!"]] [[5,5],[3]]   () :: " s t a b -> (a -> b) -> s -> t  () :: Y% s t a b -> (a -> b) -> s -> t  () ::  >$ s t a b -> (a -> b) -> s -> t  () :: = s t a b -> (a -> b) -> s -> t Replace the target of a  > or all of the targets of a   or = with a constant value. This is an infix version of !, provided for consistency with ()  f <$ a "a   f  a(a,b,c,d) & _4 .~ e (a,b,c,e)(42,"world") & _1 .~ "hello"("hello","world")(a,b) & both .~ c(c,c)   () ::  s t a b -> b -> s -> t  () :: Y s t a b -> b -> s -> t  () ::  > s t a b -> b -> s -> t  () :: = s t a b -> b -> s -> t Set the target of a  >, = or  to  a value.  l  t "a  l ( t)Nothing & id ?~ aJust aMap.empty & at 3 ?~ xfromList [(3,x)]   () ::  s t a (, b) -> b -> s -> t  () :: Y s t a (, b) -> b -> s -> t  () ::  > s t a (, b) -> b -> s -> t  () :: = s t a (, b) -> b -> s -> t Set 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  t directly is a good idea. (a,b) & _1 <.~ c (c,(c,b))-("good","morning","vietnam") & _3 <.~ "world"$("world",("good","morning","world"))K(42,Map.fromList [("goodnight","gracie")]) & _2.at "hello" <.~ Just "world"G(Just "world",(42,fromList [("goodnight","gracie"),("hello","world")]))   () ::  s t a b -> b -> s -> (b, t)  () :: Y# s t a b -> b -> s -> (b, t)  () ::  >" s t a b -> b -> s -> (b, t)  () :: = s t a b -> b -> s -> (b, t) Set to  a value 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. import Data.Map as MapF_2.at "hello" <?~ "world" $ (42,Map.fromList [("goodnight","gracie")])B("world",(42,fromList [("goodnight","gracie"),("hello","world")]))   () ::  s t a b -> (, b) -> s -> (b, t)  () :: Y s t a (, b) -> b -> s -> (b, t)  () ::  > s t a (, b) -> b -> s -> (b, t)  () :: = s t a (, b) -> b -> s -> (b, t) 0Increment the target(s) of a numerically valued  >,  or = (a,b) & _1 +~ c (a + c,b)(a,b) & both +~ c (a + c,b + c)(1,2) & _2 +~ 1(1,3)"[(a,b),(c,d)] & traverse.both +~ e[(a + e,b + e),(c + e,d + e)]   () :: Num a =>  _  s a -> a -> s -> s  () :: Num a =>  _ Y s a -> a -> s -> s  () :: Num a =>  _  > s a -> a -> s -> s  () :: Num a =>  _ = s a -> a -> s -> s /Multiply the target(s) of a numerically valued  >, Y,  or = (a,b) & _1 *~ c (a * c,b)(a,b) & both *~ c (a * c,b * c)(1,2) & _2 *~ 4(1,8)Just 24 & mapped *~ 2Just 48   () ::  a =>  _  s a -> a -> s -> s  () ::  a =>  _ Y s a -> a -> s -> s  () ::  a =>  _  > s a -> a -> s -> s  () ::  a =>  _ = s a -> a -> s -> s 0Decrement the target(s) of a numerically valued  >, Y,  or = (a,b) & _1 -~ c (a - c,b)(a,b) & both -~ c (a - c,b - c)_1 -~ 2 $ (1,2)(-1,2)"mapped.mapped -~ 1 $ [[4,5],[6,7]] [[3,4],[5,6]]   () ::  a =>  _  s a -> a -> s -> s  () ::  a =>  _ Y s a -> a -> s -> s  () ::  a =>  _  > s a -> a -> s -> s  () ::  a =>  _ = s a -> a -> s -> s -Divide the target(s) of a numerically valued  >, Y,  or = (a,b) & _1 //~ c (a / c,b)(a,b) & both //~ c (a / c,b / c)("Hawaii",10) & _2 //~ 2("Hawaii",5.0)   () ::  a =>  _  s a -> a -> s -> s  () ::  a =>  _ Y s a -> a -> s -> s  () ::  a =>  _  > s a -> a -> s -> s  () ::  a =>  _ = s a -> a -> s -> s ,Raise the target(s) of a numerically valued  >,  or =" to a non-negative integral power (1,3) & _2 ^~ 2(1,9)   () :: ( a,  e) =>  _  s a -> e -> s -> s  () :: ( a,  e) =>  _ Y s a -> e -> s -> s  () :: ( a,  e) =>  _  > s a -> e -> s -> s  () :: ( a,  e) =>  _ = s a -> e -> s -> s -Raise the target(s) of a fractionally valued  >,  or = to an integral power (1,2) & _2 ^^~ (-1)(1,0.5)   () :: ( a,  e) =>  _  s a -> e -> s -> s  () :: ( a,  e) =>  _ Y s a -> e -> s -> s  () :: ( a,  e) =>  _  > s a -> e -> s -> s  () :: ( a,  e) =>  _ = s a -> e -> s -> s /Raise the target(s) of a floating-point valued  >,  or = to an arbitrary power. (a,b) & _1 **~ c(a**c,b)(a,b) & both **~ c (a**c,b**c)_2 **~ pi $ (1,3)(1,31.54428070019754)   () ::  a =>  _  s a -> a -> s -> s  () ::  a =>  _ Y s a -> a -> s -> s  () ::  a =>  _  > s a -> a -> s -> s  () ::  a =>  _ = s a -> a -> s -> s  Logically  the target(s) of a -valued  > or  both ||~ True $ (False,True) (True,True)both ||~ False $ (False,True) (False,True)   () ::  _  s  ->  -> s -> s  () ::  _ Y s  ->  -> s -> s  () ::  _  > s  ->  -> s -> s  () ::  _ = s  ->  -> s -> s  Logically  the target(s) of a -valued  > or  both &&~ True $ (False, True) (False,True)both &&~ False $ (False, True) (False,False)   () ::  _  s  ->  -> s -> s  () ::  _ Y s  ->  -> s -> s  () ::  _  > s  ->  -> s -> s  () ::  _ = s  ->  -> s -> s Replace the target of a  > or all of the targets of a  or = in our monadic 2 state with a new value, irrespective of the old. This is an alias for (). -execState (do assign _1 c; assign _2 d) (a,b)(c,d)execState (both .= c) (a,b)(c,c)    ::  s m =>  _ Y s a -> a -> m ()   ::  s m =>  _  > s a -> a -> m ()   ::  s m =>  _ = s a -> a -> m ()   ::  s m =>  _  s a -> a -> m () Replace the target of a  > or all of the targets of a  or = in our monadic 2 state with a new value, irrespective of the old. This is an infix version of . %execState (do _1 .= c; _2 .= d) (a,b)(c,d)execState (both .= c) (a,b)(c,c)   () ::  s m =>  _ Y s a -> a -> m ()  () ::  s m =>  _  > s a -> a -> m ()  () ::  s m =>  _ = s a -> a -> m ()  () ::  s m =>  _  s a -> a -> m () 9It puts the state in the monad or it gets the hose again. Map over the target of a  > or all of the targets of a  or = in our monadic state. $execState (do _1 %= f;_2 %= g) (a,b) (f a,g b)execState (do both %= f) (a,b) (f a,f b)   () ::  s m =>  _ Y s a -> (a -> a) -> m ()  () ::  s m =>  _  > s a -> (a -> a) -> m ()  () ::  s m =>  _ = s a -> (a -> a) -> m ()  () ::  s m =>  _  s a -> (a -> a) -> m () Replace the target of a  > or all of the targets of a  or = in our monadic  state with ' a new value, irrespective of the old. -execState (do at 1 ?= a; at 2 ?= b) Map.emptyfromList [(1,a),(2,b)]1execState (do _1 ?= b; _2 ?= c) (Just a, Nothing)(Just b,Just c)   () ::  s m =>  _ Y s (, a) -> a -> m ()  () ::  s m =>  _  > s (, a) -> a -> m ()  () ::  s m =>  _ = s (, a) -> a -> m ()  () ::  s m =>  _  s (, a) -> a -> m () Modify the target(s) of a  _  >, Y,  or = by adding a value  Example:   $ fresh :: MonadState Int m => m Int  fresh = do    1  use  %execState (do _1 += c; _2 += d) (a,b) (a + c,b + d)CexecState (do _1.at 1.non 0 += 10) (Map.fromList [(2,100)],"hello")#(fromList [(1,10),(2,100)],"hello")   () :: ( s m,  a) =>  _  s a -> a -> m ()  () :: ( s m,  a) =>  _ Y s a -> a -> m ()  () :: ( s m,  a) =>  _  > s a -> a -> m ()  () :: ( s m,  a) =>  _ = s a -> a -> m () Modify the target(s) of a  _  >, Y,  or = by subtracting a value %execState (do _1 -= c; _2 -= d) (a,b) (a - c,b - d)   () :: ( s m,  a) =>  _  s a -> a -> m ()  () :: ( s m,  a) =>  _ Y s a -> a -> m ()  () :: ( s m,  a) =>  _  > s a -> a -> m ()  () :: ( s m,  a) =>  _ = s a -> a -> m () Modify the target(s) of a  _  >, Y,  or = by multiplying by value. %execState (do _1 *= c; _2 *= d) (a,b) (a * c,b * d)   () :: ( s m,  a) =>  _  s a -> a -> m ()  () :: ( s m,  a) =>  _ Y s a -> a -> m ()  () :: ( s m,  a) =>  _  > s a -> a -> m ()  () :: ( s m,  a) =>  _ = s a -> a -> m () Modify the target(s) of a  _  >, Y,  or = by dividing by a value. 'execState (do _1 //= c; _2 //= d) (a,b) (a / c,b / d)   () :: ( s m,  a) =>  _  s a -> a -> m ()  () :: ( s m,  a) =>  _ Y s a -> a -> m ()  () :: ( s m,  a) =>  _  > s a -> a -> m ()  () :: ( s m,  a) =>  _ = s a -> a -> m () ,Raise the target(s) of a numerically valued  >,  or =# to a non-negative integral power.   () :: ( s m,  a,  e) =>  _  s a -> e -> m ()  () :: ( s m,  a,  e) =>  _ Y s a -> e -> m ()  () :: ( s m,  a,  e) =>  _  > s a -> e -> m ()  () :: ( s m,  a,  e) =>  _ = s a -> e -> m () ,Raise the target(s) of a numerically valued  >,  or = to an integral power.   () :: ( s m,  a,  e) =>  _  s a -> e -> m ()  () :: ( s m,  a,  e) =>  _ Y s a -> e -> m ()  () :: ( s m,  a,  e) =>  _  > s a -> e -> m ()  () :: ( s m,  a,  e) =>  _ = s a -> e -> m () ,Raise the target(s) of a numerically valued  >,  or = to an arbitrary power 'execState (do _1 **= c; _2 **= d) (a,b) (a**c,b**d)   () :: ( s m,  a) =>  _  s a -> a -> m ()  () :: ( s m,  a) =>  _ Y s a -> a -> m ()  () :: ( s m,  a) =>  _  > s a -> a -> m ()  () :: ( s m,  a) =>  _ = s a -> a -> m () Modify the target(s) of a  _  >, Y,  or = by taking their logical  with a value [execState (do _1 &&= True; _2 &&= False; _3 &&= True; _4 &&= False) (True,True,False,False)(True,False,False,False)   () ::  s m =>  _  s  ->  -> m ()  () ::  s m =>  _ Y s  ->  -> m ()  () ::  s m =>  _  > s  ->  -> m ()  () ::  s m =>  _ = s  ->  -> m () Modify the target(s) of a  _  >, 'Iso,  or = by taking their logical  with a value [execState (do _1 ||= True; _2 ||= False; _3 ||= True; _4 ||= False) (True,True,False,False)(True,True,True,False)   () ::  s m =>  _  s  ->  -> m ()  () ::  s m =>  _ Y s  ->  -> m ()  () ::  s m =>  _  > s  ->  -> m ()  () ::  s m =>  _ = s  ->  -> m () 6Run a monadic action, and set all of the targets of a  >,  or = to its result.    () ::  s m => Y s s a b -> m b -> m ()  () ::  s m =>  > s s a b -> m b -> m ()  () ::  s m => = s s a b -> m b -> m ()  () ::  s m =>  s s a b -> m b -> 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  >, , 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   () ::  s m =>  s s a b -> b -> m b  () ::  s m => Y s s a b -> b -> m b  () ::  s m =>  > s s a b -> b -> m b  () ::  s m => = s s a b -> b -> m b Set  a value with pass-through XThis is useful for chaining assignment without round-tripping through your monad stack.  do x <- at foo <*?= 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   () ::  s m =>  s s a (, b) -> b -> m b  () ::  s m => Y s s a (, b) -> b -> m b  () ::  s m =>  > s s a (, b) -> b -> m b  () ::  s m => = s s a (, b) -> b -> m b ,Modify the target of a monoidally valued by ing another value. (Sum a,b) & _1 <>~ Sum c(Sum {getSum = a + c},b)(Sum a,Sum b) & both <>~ Sum c+(Sum {getSum = a + c},Sum {getSum = b + c})"both <>~ "!!!" $ ("hello","world")("hello!!!","world!!!")   () :: > a =>  s t a a -> a -> s -> t  () :: > a =>  s t a a -> a -> s -> t  () :: > a => Lens s t a a -> a -> s -> t  () :: > a =>  Traversal s t a a -> a -> s -> t Modify the target(s) of a  _ Lens, ,  or  Traversal by  ing a value. ?execState (do _1 <>= Sum c; _2 <>= Product d) (Sum a,Product b)3(Sum {getSum = a + c},Product {getProduct = b * d}),execState (both <>= "!!!") ("hello","world")("hello!!!","world!!!")   () :: ( s m, > a) =>  _  s a -> a -> m ()  () :: ( s m, > a) =>  _  s a -> a -> m ()  () :: ( s m, > a) =>  _ Lens s a -> a -> m ()  () :: ( s m, > a) =>  _  Traversal s a -> a -> m () /{|}~1 {|}~1|}~{ -{|}~ Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy*Useful for storing getters in containers. @When you see this in a type signature it indicates that you can  pass the function a  >, ,  =,  Z,  7, Y , or one of ( the indexed variants, and it will just "do the right thing". Most - combinators are able to be used with both a  or a   Z2 in limited situations, to do so, they need to be 2 monomorphic in what we are going to extract with Const. To be compatible  with  >, = and  Y. we also restricted choices of the irrelevant t and  b parameters. If a function accepts a  r s t a b , then when r is a Monoid, then  you can pass a  Z (or  =&), otherwise you can only pass this a   or  >. A ? describes how to retrieve a single value in a way that can be . composed with other lens-like constructions.  Unlike a  > a  is read-only. Since a  L cannot be used to write back there are no lens laws that can be applied to = it. In fact, it is isomorphic to an arbitrary function from (a -> s).  Moreover, a  can be used directly as a  Z,  since it just ignores the  Applicative. ^Passes the result of the left side to the function on the right side (forward pipe operator).  This is the flipped version of (+), which is more common in languages like F# as (|>) where it is needed e for inference. Here it is supplied for notational convenience and given a precedence that allows it  to be nested inside uses of (). a & ff a"hello" & length & succ6UThis combinator is commonly used when applying multiple lens operations in sequence. =("hello","world") & _1.element 0 .~ 'j' & _1.element 4 .~ 'y'("jelly","world") This reads somewhat similar to: Nflip execState ("hello","world") $ do _1.element 0 .= 'j'; _1.element 4 .= 'y'("jelly","world")A version of (=) with much tighter precedence that can be interleaved with () a ^& ff a"hello" ^& length5&("hello","world")^._1^&reverse^?!_head'o'Build a % from an arbitrary Haskell function.   f .  g "a  (g . f) a   f "a f aa ^.to ff a("hello","world")^.to snd"world" 5^.to succ6(0, -5)^._2.to abs5View the value pointed to by a , Y or   >4 or the result of folding over all the results of a   Z or = that points  at a monoidal values.   .  "a  view (to f) af aview _2 (1,"hello")"hello"view (to succ) 56&view (_2._1) ("hello",("world","!!!"))"world"As views, is commonly used to access the target of a 2 or obtain a monoidal summary of the targets of a Fold, U It may be useful to think of it as having one of these more restrictive signatures:     ::  s a -> s -> a   :: Monoid m =>  Z s m -> s -> m   ::  _ Y s a -> s -> a   ::  _  > s a -> s -> a   :: Monoid m =>  _ = s m -> s -> m \In a more general setting, such as when working with a monad transformer stack you can use:    ::  s m =>  s a -> m a   :: ( s m, Monoid a) =>  Z s a -> m a   ::  s m =>  _ Y s a -> m a   ::  s m =>  _  > s a -> m a   :: ( s m, Monoid a) =>  _ = s a -> m a View the value of a , Y,   >5 or the result of folding over the result of mapping  the targets of a  Z or  =. It may be useful to think of " as having these more restrictive  signatures:   l f "a  (l   f)views (to f) g ag (f a)views _2 length (1,"hello")5As views, is commonly used to access the target of a 2 or obtain a monoidal summary of the targets of a Fold, U It may be useful to think of it as having one of these more restrictive signatures:     :: ' s a -> (a -> r) -> s -> r   :: Monoid m =>  Z) s a -> (a -> m) -> s -> m   ::  _ Y# s a -> (a -> r) -> s -> r   ::  _  >" s a -> (a -> r) -> s -> r   :: Monoid m =>  _ = s a -> (a -> m) -> s -> m \In a more general setting, such as when working with a monad transformer stack you can use:    ::  s m =>  s a -> m a   :: ( s m, Monoid a) =>  Z s a -> m a   ::  s m =>  _ Y s a -> m a   ::  s m =>  _  > s a -> m a   :: ( s m, Monoid a) =>  _ = s a -> m a View the value pointed to by a , Y or   >4 or the result of folding over all the results of a   Z or = that points  at a monoidal values. This is the same operation as , only infix.   f  x "a f x to f ^$ xf x_2 ^$ (1, "hello")"hello"   () ::  s a -> s -> a  () :: Monoid m =>  Z s m -> s -> m  () ::  _ Y s a -> s -> a  () ::  _  > s a -> s -> a  () :: Monoid m =>  _ = s m -> s -> m View the value pointed to by a  or  > or the - result of folding over all the results of a  Z or  =# that points at a monoidal values. This is the same operation as  with the arguments flipped. HThe fixity and semantics are such that subsequent field accesses can be  performed with ()  (a,b)^._2b("hello","world")^._2"world"import Data.Complex$((0, 1 :+ 2), 3)^._1._2.to magnitude2.23606797749979   () :: s ->  s a -> a  () :: Monoid m => s ->  Z s m -> m  () :: s ->  _ Y s a -> a  () :: s ->  _  > s a -> a  () :: Monoid m => s ->  _ = s m -> m Use the target of a  >, Y, or  - in the current state, or use a summary of a   Z or = that points  to a monoidal value. evalState (use _1) (a,b)a$evalState (use _1) ("hello","world")"hello"    ::  s m =>  s a -> m a   :: ( s m, Monoid r) =>  Z s r -> m r   ::  s m =>  _ Y s a -> m a   ::  s m =>  _  > s a -> m a   :: ( s m, Monoid r) =>  _ = s r -> m r Use the target of a  >, Y or  - in the current state, or use a summary of a   Z or = that  points to a monoidal value. ,evalState (uses _1 length) ("hello","world")5    ::  s m => " s a -> (a -> r) -> m r   :: ( s m, Monoid r) =>  Z$ s a -> (a -> r) -> m r   ::  s m =>  _  > s a -> (a -> r) -> m r   ::  s m =>  _ Y s a -> (a -> r) -> m r   :: ( s m, Monoid r) =>  _ = s a -> (a -> r) -> m r %This is a type restricted version of  that expects a Simple . Use the target of a  _  >, Y, or  - in the current state, or use a summary of a   Z or = that points  to a monoidal value. _This use of this combinator may aid type-inference when working with lenses or traversals that @ have non-defaultable typeclass constraints on their arguments. evalState (use' _1) (a,b)a%evalState (use' _1) ("hello","world")"hello"    ::  s m =>  s a -> m a   :: ( s m, Monoid r) =>  Z s r -> m r   ::  s m =>  _ Y s a -> m a   ::  s m =>  _  > s a -> m a   :: ( s m, Monoid r) =>  _ = s r -> m r %This is a type restricted version of  that expects a Simple . Use the target of a  >, Y or  - in the current state, or use a summary of a   Z or = that  points to a monoidal value. -evalState (uses' _1 length) ("hello","world")5    ::  s m => " s a -> (a -> r) -> m r   :: ( s m, Monoid r) =>  Z$ s a -> (a -> r) -> m r   ::  s m =>  _  > s a -> (a -> r) -> m r   ::  s m =>  _ Y s a -> (a -> r) -> m r   :: ( s m, Monoid r) =>  _ = s a -> (a -> r) -> m r %This is a type restricted version of  that expects a Simple . View the value pointed to by a , Y or   >4 or the result of folding over all the results of a   Z or = that points  at a monoidal values.   .  "a view' (to f) af aview' _2 (1,"hello")"hello"view' (to succ) 56'view' (_2._1) ("hello",("world","!!!"))"world"As , is commonly used to access the target of a 2 or obtain a monoidal summary of the targets of a Fold, U It may be useful to think of it as having one of these more restrictive signatures:     ::  s a -> s -> a   :: Monoid m =>  Z s m -> s -> m   ::  _ Y s a -> s -> a   ::  _  > s a -> s -> a   :: Monoid m =>  _ = s m -> s -> m \In a more general setting, such as when working with a monad transformer stack you can use:    ::  s m =>  s a -> m a   :: ( s m, Monoid a) =>  Z s a -> m a   ::  s m =>  _ Y s a -> m a   ::  s m =>  _  > s a -> m a   :: ( s m, Monoid a) =>  _ = s a -> m a %This is a type restricted version of  that expects a Simple . View the value of a , Y,   >5 or the result of folding over the result of mapping  the targets of a  Z or  =. It may be useful to think of perviews" as having these more restrictive  signatures:   l f "a  (l   f)views' _2 length (1,"hello")5As , is commonly used to access the target of a 2 or obtain a monoidal summary of the targets of a Fold, U It may be useful to think of it as having one of these more restrictive signatures:     :: ' s a -> (a -> r) -> s -> r   :: Monoid m =>  Z) s a -> (a -> m) -> s -> m   ::  _ Y# s a -> (a -> r) -> s -> r   ::  _  >" s a -> (a -> r) -> s -> r   :: Monoid m =>  _ = s a -> (a -> m) -> s -> m \In a more general setting, such as when working with a monad transformer stack you can use:    ::  s m => " s a -> (a -> r) -> m r   :: ( s m, Monoid a) =>  Z$ s a -> (a -> r) -> m r   ::  s m =>  _ Y s a -> (a -> r) -> m r   ::  s m =>  _  > s a -> (a -> r) -> m r   :: ( s m, Monoid a) =>  _ = s a -> (a -> r) -> m r && portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferredThis % can be used to change the type of a  by mapping  the elements to new values. Sadly, you can't create a valid = for a , but you can  manipulate it by reading using  g and reindexing it via . (over setmapped (+1) (fromList [1,2,3,4])fromList [2,3,4,5]Construct a set from a Getter,  Z, =,  > or Y. 5setOf (folded._2) [("hello",1),("world",2),("!!!",3)]fromList [1,2,3]    :: Getter s a -> s ->  a   ::  a =>  Z s a -> s ->  a   ::  _ Y s a -> s ->  a   ::  _  > s a -> s ->  a   ::  a =>  _ = s a -> s ->  a  portable provisionalEdward Kmett <ekmett@gmail.com> TrustworthyThis % can be used to change the type of a  by mapping  the elements to new values. Sadly, you can't create a valid = for a Set, but you can  manipulate it by reading using folded and reindexing it via . (over setmapped (+1) (fromList [1,2,3,4])fromList [2,3,4,5]Construct a set from a ,  Z, =,  > or Y. 5setOf (folded._2) [("hello",1),("world",2),("!!!",3)]fromList [1,2,3]    ::  a =>  s a -> s ->  a   :: ( a,  a) =>  Z s a -> s ->  a   ::  a =>  _ Y s a -> s ->  a   ::  a =>  _  > s a -> s ->  a   :: ( a,  a) =>  _ = s a -> s ->  a  portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferredA strict version of () for monads. (+1) <$!> [1,2,3,4] [2,3,4,5]A strict version of (hi) for monads. () <$! [1,2,3,4] [(),(),(),()]Infix flipped fmap. () = A 3  Rank2Types provisionalEdward Kmett <ekmett@gmail.com>None- type  =  )Useful for storing lenses in containers. type  k f s a =  ( k f) s a type  f s t a b =  (->) f s t a bMany 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 s t a b for some / f,  then they may be passed a .  Further, if f is an 0, 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.    %j ::   (kl a) a  (m ::  n= [a] a .Note: To use this alias in your own code with  f or  9, 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  is subject to the  three common sense lens laws: !1) You get back what you put in:  o l (p l b a) "a b"2) Putting back what you got doesn't change anything:  p l (o l a) a "a a.3) Setting twice is the same as setting once:  p l c (p l b a) "a p l c a=These laws are strong enough that the 4 type parameters of a  cannot C 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 9 or  =. You can also use a  for q as if it were a   Z or <. Since every lens is a valid =, the 7 traversal laws are required of any lenses you create:    l  "a   3 (l f)  l g "a rs  l (rt  3 f  g)  type  s t a b = forall f. / f =>  f s t a bBuild a  from a getter and a setter.   :: /9 f => (s -> a) -> (s -> b -> t) -> (a -> f b) -> s -> f ts ^. lens getter settergetter ss & lens getter setter .~ b setter s bs & lens getter setter %~ fsetter s (f (getter s))(') 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:  () "a    () :: / f => Y) s t a b -> (a -> f b) -> s -> f t  () :: / f => ( s t a b -> (a -> f b) -> s -> f t  () :: 0 f => =# s t a b -> (a -> f b) -> s -> f t DIt 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 supplemental monoidal summary  of its actions, by choosing  f = ((,) m)   () :: Y/ s t a b -> (a -> (r, b)) -> s -> (r, t)  () :: . s t a b -> (a -> (r, b)) -> s -> (r, t)  () :: > m => =) s t a b -> (a -> (m, b)) -> s -> (m, t) Modify the target of a + in the current state returning some extra  information of type r or modify all targets of a  =( in the current state, extracting extra  information of type r/ and return a monoidal summary of the changes. (runState (_1 %%= \x -> (f x, g x)) (a,b) (f a,(g a,b)) () "a ( )It may be useful to think of ($), instead, as having either of the , following more restricted type signatures:   () ::  s m => Y' s s a b -> (a -> (r, b)) -> m r  () ::  s m => & s s a b -> (a -> (r, b)) -> m r  () :: ( s m, > r) => =! s s a b -> (a -> (r, b)) -> m r Lift a ! so it can run under a function. 9Merge two lenses, getters, setters, folds or traversals.   "a       :: < s a -> < s' a -> < (+ s s') a   ::  Z s a ->  Z s' a ->  Z (+ s s') a   ::   s a ->   s' a ->   (+ s s') a   ::  = s a ->  = s' a ->  = (+ s s') a   ::  9 s a ->  9 s' a ->  9 (+ s s') a  This is a  that updates either side of an +', where both sides have the same type.   "a   Left a^.chosenaRight a^.chosenaRight "hello"^.chosen"hello"Right a & chosen *~ b Right (a * b) makes a  from two other lenses. *(Left a, Right b)^.alongside chosen chosen(a,b)4(Left a, Right b) & alongside chosen chosen .~ (c,d)(Left c,Right d)  ::  s t a b ->  s' t' a' b' ->  (s,s') (t,t') (a,a') (b,b')This  lets you view the current  of any   @ and ) to a new position. This reduces the API  for working with a  instances to a single .     w "a w ^.    s w "a w &  .~ s   f w "a w &  %~ f     :: Simple Lens (2 s s a) s  Cloning a ! is one way to make sure you aren't given  something weaker, such as a = and can be D used as a way to pass around lenses that have to be monomorphic in f. !Note: This only accepts a proper . J :t let example l x = set (cloneLens l) (x^.cloneLens l + 1) x in example G let example l x = set (cloneLens l) (x^.cloneLens l + 1) x in example 8 :: Num b => LensLike (Context b b) s t b b -> s -> t Modify the target of a  and return the result 2When you do not need the result of the addition, (u) is more flexible.   () :: ) s t a b -> (a -> b) -> s -> (b, t)  () :: Y* s t a b -> (a -> b) -> s -> (b, t)  () :: > b => =$ s t a b -> (a -> b) -> s -> (b, t) -Increment the target of a numerically valued  and return the result 2When you do not need the result of the addition, (v) is more flexible.   () ::  a =>   s a -> a -> s -> (a, s)  () ::  a =>  Y s a -> a -> s -> (a, s) -Decrement the target of a numerically valued  and return the result 5When you do not need the result of the subtraction, (w) is more flexible.   () ::  a =>   s a -> a -> s -> (a, s)  () ::  a =>  Y s a -> a -> s -> (a, s) ,Multiply the target of a numerically valued  and return the result 8When you do not need the result of the multiplication, (x ) is more  flexible.   () ::  b =>   s a -> a -> a -> (s, a)  () ::  b =>  Y s a -> a -> a -> (s, a)) +Divide the target of a fractionally valued  and return the result. 2When you do not need the result of the division, (y) is more flexible.   () ::  b =>   s a -> a -> a -> (s, a)  () ::  b =>  Y s a -> a -> a -> (s, a)) )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, (z) is more flexible.   () :: ( b,  e) =>   s a -> e -> a -> (a, s)  () :: ( b,  e) =>  Y s a -> e -> a -> (a, s) *Raise the target of a fractionally valued  to an  power  and return the result. 2When you do not need the result of the division, ({) is more flexible.   () :: ( b,  e) =>   s a -> e -> a -> (a, s)  () :: ( b,  e) =>  Y s a -> e -> a -> (a, s) ,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, (|) is more flexible.   () ::  a =>   s a -> a -> s -> (a, s)  () ::  a =>  Y s a -> a -> s -> (a, s)  Logically  a Boolean valued  and return the result 3When you do not need the result of the operation, (}) is more flexible.   () ::   s  ->  -> s -> (, s)  () ::  Y s  ->  -> s -> (, s)  Logically  a Boolean valued  and return the result 3When you do not need the result of the operation, (~) is more flexible.   () ::   s  ->  -> s -> (, s)  () ::  Y s  ->  -> s -> (, s) Modify the target of a , but return the old value. 2When you do not need the result of the addition, (u) is more flexible.   () :: ) s t a b -> (a -> b) -> s -> (b, t)  () :: Y* s t a b -> (a -> b) -> s -> (b, t)  () :: > b => =$ s t a b -> (a -> b) -> s -> (b, t) Modify the target of a , but return the old value. %When you do not need the old value, (u) is more flexible.   () :: " s t a b -> b -> s -> (a, t)  () :: Y# s t a b -> b -> s -> (a, t)  () :: > b => = s t a b -> b -> s -> (a, t) Modify the target of a  into your monad's state by a user supplied ! function and return the result. When applied to a =D, it this will return a monoidal summary of all of the intermediate  results. 3When you do not need the result of the operation, () is more flexible.   () ::  s m =>   s a -> (a -> a) -> m a  () ::  s m =>  Y s a -> (a -> a) -> m a  () :: ( s m, > a) =>   Traversal s a -> (a -> a) -> m a *Add to the target of a numerically valued  into your monad's state  and return the result. 2When you do not need the result of the addition, ( ) is more  flexible.   () :: ( s m,  a) =>   s a -> a -> m a  () :: ( s m,  a) =>  Y s a -> a -> m a 1Subtract from the target of a numerically valued  into your monad's  state and return the result. 5When you do not need the result of the subtraction, ( ) is more  flexible.   () :: ( s m,  a) =>   s a -> a -> m a  () :: ( s m,  a) =>  Y s a -> a -> m a ,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, ( ) is more  flexible.   () :: ( s m,  a) =>   s a -> a -> m a  () :: ( s m,  a) =>  Y s a -> a -> m a +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, () is more flexible.   () :: ( s m,  a) =>   s a -> a -> m a  () :: ( s m,  a) =>  Y s a -> a -> m a )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, () is more flexible.   () :: ( s m,  a,  e) =>   s a -> e -> m a  () :: ( s m,  a,  e) =>  Y s a -> e -> m a *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, () is more flexible.   () :: ( s m,  b,  e) =>   s a -> e -> m a  () :: ( s m,  b,  e) =>  Y s a -> e -> m a ,Raise the target of a floating-point valued  into your monad's 4 state to an arbitrary power and return the result. 3When you do not need the result of the operation, () is more flexible.   () :: ( s m,  a) =>   s a -> a -> m a  () :: ( s m,  a) =>  Y s a -> a -> m a  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.   () ::  s m =>   s  ->  -> m   () ::  s m =>  Y s  ->  -> m   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.   () ::  s m =>   s  ->  -> m   () ::  s m =>  Y s  ->  -> m  Modify the target of a  into your monad's state by a user supplied  function and return the old value that was replaced. When applied to a =B, it this will return a monoidal summary of all of the old values  present. 3When you do not need the result of the operation, () is more flexible.   () ::  s m =>   s a -> (a -> a) -> m a  () ::  s m =>  Y s a -> (a -> a) -> m a  () :: ( s m, > b) =>   Traversal s a -> (a -> a) -> m a Modify the target of a  into your monad's state by a user supplied  function and return the old value that was replaced. When applied to a =B, it this will return a monoidal summary of all of the old values  present. 3When you do not need the result of the operation, () is more flexible.   () ::  s m =>   s a -> (a -> a) -> m a  () ::  s m =>  Y s a -> (a -> a) -> m a  () :: ( s m, > t) =>   Traversal s a -> (a -> a) -> m a ,Run a monadic action, and set the target of  to its result.    () ::  s m => Y s s a b -> m b -> m b  () ::  s m =>  s s a b -> m b -> m b (NB: This is limited to taking an actual  than admitting a = because 5 there are potential loss of state issues otherwise. 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, (<>~) 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. /123123-  Rank2Types provisionalEdward Kmett <ekmett@gmail.com>None:(Useful for storing folds in containers. A I describes how to retrieve multiple values in a way that can be composed % with other lens-like constructions. A  s aC 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 a), then there should be a  fooOf method that takes a  s a and a value of type s. A  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 . [1,2,3,4]^..folding tail[2,3,4] Obtain a  from any . Just 3^..folded[3]Nothing^..folded[][(1,2),(3,4)]^..folded.both [1,2,3,4]%Fold by repeating the input forever.   "a  5^..taking 20 repeated)[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]!A fold that replicates its input n times.   n "a  ( n)5^..replicated 20)[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]ITransform a fold into a fold that loops over its elements over and over. $[1,2,3]^..taking 7 (cycled traverse)[1,2,3,1,2,3,1]2Build a fold that unfolds its values from a seed.   "a  . ?10^..unfolded (\b -> if b == 0 then Nothing else Just (b, b-1))[10,9,8,7,6,5,4,3,2,1]x ^.  f5 Return an infinite fold of repeated applications of f to x.  ( f) a "a  f a Obtain a - that can be composed with to filter another , Y, ,  (or =) Note: This is not a legal =M, unless you are very careful not to invalidate the predicate on the target. *As a counter example, consider that given evens =   the second = law is violated:  over evens   over evens  /= over evens (  ),So, in order for this to qualify as a legal  TraversalL you can only use it for actions that preserve the result of the predicate!  :: (a -> ) ->  a a.This allows you to traverse the elements of a = or  in the opposite order.  This will demote an V or W to a regular = or , , respectively; to preserve the indices, use  instead. Note:  should have no impact on a , 9,  or Y. To change the direction of an Y, use .  Obtain a ! by taking elements from another , , Y,  or = while a predicate holds.   p "a  ( p ))toListOf (takingWhile (<=3) folded) [1..][1,2,3] Obtain a # by dropping elements from another , , Y,  or = while a predicate holds.   p "a  ( p ),toListOf (droppingWhile (<=3) folded) [1..6][4,5,6]-toListOf (droppingWhile (<=3) folded) [1,6,1][6,1]  =    "a     :: % s a -> (a -> r) -> s -> r   :: > r => ' s a -> (a -> r) -> s -> r   ::   s a -> (a -> r) -> s -> r   ::  Y! s a -> (a -> r) -> s -> r   :: > r =>  = s a -> (a -> r) -> s -> r   :: > r =>  7 s a -> (a -> r) -> s -> r   =    "a     ::  s m -> s -> m   :: > m =>  s m -> s -> m   ::   s m -> s -> m   ::  Y s m -> s -> m   :: > m =>  = s m -> s -> m   :: > m =>  7 s m -> s -> m IRight-associative fold of parts of a structure that are viewed through a , ,  or =.   "a      :: / s a -> (a -> r -> r) -> r -> s -> r   :: 1 s a -> (a -> r -> r) -> r -> s -> r   ::  * s a -> (a -> r -> r) -> r -> s -> r   ::  Y+ s a -> (a -> r -> r) -> r -> s -> r   ::  =% s a -> (a -> r -> r) -> r -> s -> r   ::  7) s a -> (a -> r -> r) -> r -> s -> r LLeft-associative fold of the parts of a structure that are viewed through a , ,  or =.   "a      :: / s a -> (r -> a -> r) -> r -> s -> r   :: 1 s a -> (r -> a -> r) -> r -> s -> r   ::  * s a -> (r -> a -> r) -> r -> s -> r   ::  Y+ s a -> (r -> a -> r) -> r -> s -> r   ::  =% s a -> (r -> a -> r) -> r -> s -> r   ::  7) s a -> (r -> a -> r) -> r -> s -> r #Extract a list of the targets of a  . See also ().    "a    () "a A  (A convenient infix (flipped) version of . [[1,2],[3]]^..traverse.traverse[1,2,3] (1,2)^..both[1,2]    xs "a xs    () "a A     ( ) :: s ->  s a -> [a]  ( ) :: s ->  s a -> [a]  ( ) :: s ->   s a -> [a]  ( ) :: s ->  Y s a -> [a]  ( ) :: s ->  = s a -> [a]  ( ) :: s ->  7 s a -> [a] Returns  if every target of a  is . andOf both (True,False)FalseandOf both (True,True)True  "a      ::  s  -> s ->    ::  s  -> s ->    ::   s  -> s ->    ::  Y s  -> s ->    ::  = s  -> s ->    ::  7 s  -> s ->  Returns  if any target of a  is . orOf both (True,False)TrueorOf both (False,False)False  "a      ::  s  -> s ->    ::  s  -> s ->    ::   s  -> s ->    ::  Y s  -> s ->    ::  = s  -> s ->    ::  7 s  -> s ->   Returns  if any target of a  satisfies a predicate. anyOf both (=='x') ('x','y')Trueimport Data.Data.Lens=anyOf biplate (== "world") (((),2::Int),"hello",("world",11))True  "a        ::  s a -> (a ->  ) -> s ->     ::  s a -> (a ->  ) -> s ->     ::   s a -> (a ->  ) -> s ->     ::  Y s a -> (a ->  ) -> s ->     ::  = s a -> (a ->  ) -> s ->     ::  7 s a -> (a ->  ) -> s ->   Returns  if every target of a  satisfies a predicate. allOf both (>=3) (4,5)TrueallOf folded (>=2) [1..10]False  "a        ::  s a -> (a ->  ) -> s ->     ::  s a -> (a ->  ) -> s ->     ::   s a -> (a ->  ) -> s ->     ::  Y s a -> (a ->  ) -> s ->     ::  = s a -> (a ->  ) -> s ->     ::  7 s a -> (a ->  ) -> s ->   4Calculate the product of every number targeted by a  productOf both (4,5)20productOf folded [1,2,3,4,5]120  "a        ::  s a -> s -> a    ::  a =>  s a -> s -> a    ::   s a -> s -> a    ::  Y s a -> s -> a    ::  a =>  = s a -> s -> a    ::  a =>  7 s a -> s -> a  0Calculate the sum of every number targeted by a . sumOf both (5,6)11sumOf folded [1,2,3,4]10!sumOf (folded.both) [(1,2),(3,4)]10import Data.Data.Lens8sumOf biplate [(1::Int,[]),(2,[(3::Int,4::Int)])] :: Int10  "a        _1 :: (a, b) -> a    ( . _1) :: ( f,  a) => f (a, b) -> a      ::  s a -> s -> a    ::  a =>  s a -> s -> a    ::   s a -> s -> a    ::  Y s a -> s -> a    ::  a =>  = s a -> s -> a    ::  a =>  7 s a -> s -> a  &Traverse over all of the targets of a  (or ), computing an 0 (or /) -based answer,  but unlike # do not construct a new structure.   generalizes   to work over any . When passed a ,   can work over any /, but when passed a ,   requires  an 0. +traverseOf_ both putStrLn ("hello","world")helloworld  "a        _2 :: /# f => (c -> f r) -> (d, c) -> f ()     :: 0 f => (a -> f b) -> + a c -> f () !The rather specific signature of  6 allows it to be used as if the signature was any of:     :: / f => * s a -> (a -> f r) -> s -> f ()    :: 0 f => , s a -> (a -> f r) -> s -> f ()    :: / f =>  % s a -> (a -> f r) -> s -> f ()    :: / f =>  Y& s a -> (a -> f r) -> s -> f ()    :: 0 f =>  = s a -> (a -> f r) -> s -> f ()    :: 0 f =>  7$ s a -> (a -> f r) -> s -> f () &Traverse over all of the targets of a  (or ), computing an 0 (or /) -based answer,  but unlike # do not construct a new structure.  generalizes   to work over any . When passed a ,  can work over any /, but when passed a ,  requires  an 0.   "a  !The rather specific signature of 6 allows it to be used as if the signature was any of:    :: / f => * s a -> s -> (a -> f r) -> f ()   :: 0 f => , s a -> s -> (a -> f r) -> f ()   :: / f =>  % s a -> s -> (a -> f r) -> f ()   :: / f =>  Y& s a -> s -> (a -> f r) -> f ()   :: 0 f =>  = s a -> s -> (a -> f r) -> f ()   :: 0 f =>  7$ s a -> s -> (a -> f r) -> f () &Evaluate each action in observed by a : on a structure from left to right, ignoring the results.   "a      :: / f =>  s (f a) -> s -> f ()   :: 0 f => " s (f a) -> s -> f ()   :: / f =>   s (f a) -> s -> f ()   :: / f =>   s (f a) -> s -> f ()   :: 0 f =>  = s (f a) -> s -> f ()   :: 0 f =>  7 s (f a) -> s -> f () Map each target of a h on a structure to a monadic action, evaluate these actions from left to right, and ignore the results.  B "a      ::  m => * s a -> (a -> m r) -> s -> m ()   ::  m => , s a -> (a -> m r) -> s -> m ()   ::  m =>  % s a -> (a -> m r) -> s -> m ()   ::  m =>  Y& s a -> (a -> m r) -> s -> m ()   ::  m =>  = s a -> (a -> m r) -> s -> m ()   ::  m =>  7$ s a -> (a -> m r) -> s -> m ()  is $ with two of its arguments flipped.   "a      ::  m => * s a -> s -> (a -> m r) -> m ()   ::  m => , s a -> s -> (a -> m r) -> m ()   ::  m =>  % s a -> s -> (a -> m r) -> m ()   ::  m =>  Y& s a -> s -> (a -> m r) -> m ()   ::  m =>  = s a -> s -> (a -> m r) -> m ()   ::  m =>  7$ s a -> s -> (a -> m r) -> m () -Evaluate each monadic action referenced by a > on the structure from left to right, and ignore the results.   "a      ::  m =>  s (m a) -> s -> m ()   ::  m => " s (m a) -> s -> m ()   ::  m =>   s (m a) -> s -> m ()   ::  m =>  Y s (m a) -> s -> m ()   ::  m =>  = s (m a) -> s -> m ()   ::  m =>  7 s (m a) -> s -> m () 1The sum of a collection of actions, generalizing .   "a      ::  f =>  s a -> s -> f a   ::  f =>  s a -> s -> f a   ::  f =>   s a -> s -> f a   ::  f =>  Y s a -> s -> f a   ::  f =>  = s a -> s -> f a   ::  f =>  7 s a -> s -> f a 1The sum of a collection of actions, generalizing .   "a      ::  m =>  s a -> s -> m a   ::  m =>  s a -> s -> m a   ::  m =>   s a -> s -> m a   ::  m =>  Y s a -> s -> m a   ::  m =>  = s a -> s -> m a   ::  m =>  7 s a -> s -> m a /Does the element occur anywhere within a given  of the structure? %elemOf both "hello" ("hello","world")True  "a      ::  a =>  s a -> a -> s ->    ::  a =>  s a -> a -> s ->    ::  a =>   s a -> a -> s ->    ::  a =>  Y s a -> a -> s ->    ::  a =>  = s a -> a -> s ->    ::  a =>  7 s a -> a -> s ->  3Does the element not occur anywhere within a given  of the structure?   "a      ::  a =>  s a -> a -> s ->    ::  a =>  s a -> a -> s ->    ::  a =>  Y s a -> a -> s ->    ::  a =>   s a -> a -> s ->    ::  a =>  = s a -> a -> s ->    ::  a =>  7 s a -> a -> s ->  )Map a function over all the targets of a 5 of a container and concatenate the resulting lists.   "a      ::  s a -> (a -> [r] ) -> s -> [r]   ::  s a -> (a -> [r] ) -> s -> [r]   ::   s a -> (a -> [r] ) -> s -> [r]   ::  Y s a -> (a -> [r] ) -> s -> [r]   ::  = s a -> (a -> [r] ) -> s -> [r] +Concatenate all of the lists targeted by a  into a longer list. concatOf both ("pan","ama")"panama"    "a     "a      ::  s [r] -> s -> [r]   ::  s [r] -> s -> [r]   ::  Y s [r] -> s -> [r]   ::   s [r] -> s -> [r]   ::  = s [r] -> s -> [r] ;Note: this can be rather inefficient for large containers.   "a  lengthOf _1 ("hello",())1  ( . ) ::  f => f (g a) -> ?    ::  s a -> s -> ?   ::  s a -> s -> ?   ::   s a -> s -> ?   ::  Y s a -> s -> ?   ::  = s a -> s -> ? A deprecated alias for  Perform a safe  of a  or = or retrieve  the result  from a  or .  When using a = as a partial , or a  as a partial  this can be a convenient $ way to extract the optional value.  () "a A ,   ( ) :: s ->  s a -> , a  ( ) :: s ->  s a -> , a  ( ) :: s ->   s a -> , a  ( ) :: s ->  Y s a -> , a  ( ) :: s ->  = s a -> , a Perform an *UNSAFE*  of a  or = assuming that it is there.   ( ) :: s ->  s a -> a  ( ) :: s ->  s a -> a  ( ) :: s ->   s a -> a  ( ) :: s ->  Y s a -> a  ( ) :: s ->  = s a -> a  Retrieve the  entry of a  or = or retrieve  the result  from a  or .    ::  s a -> s -> , a   ::  s a -> s -> , a   ::   s a -> s -> , a   ::  Y s a -> s -> , a   ::  = s a -> s -> , a  Retrieve the  entry of a  or = or retrieve  the result  from a  or .    ::  s a -> s -> , a   ::  s a -> s -> , a   ::   s a -> s -> , a   ::  Y s a -> s -> , a   ::  = s a -> s -> , a Returns  if this  or =( has no targets in the given container. Note:  on a valid Y,  or  should always return    "a  /This may be rather inefficient compared to the  check of many containers. nullOf _1 (1,2)False  (  _1  ) ::  f => f (g a, b) ->     ::  s a -> s ->    ::  s a -> s ->    ::  Y s a -> s ->    ::   s a -> s ->    ::  = s a -> s ->   Returns  if this  or =) has any targets in the given container. Note:   on a valid Y,  or  should always return    "a   /This may be rather inefficient compared to the  .  check of many containers. notNullOf _1 (1,2)True   (  _1  ) ::  f => f (g a, b) ->      ::  s a -> s ->     ::  s a -> s ->     ::  Y s a -> s ->     ::   s a -> s ->     ::  = s a -> s ->  !2Obtain the maximum element (if any) targeted by a  or = Note: maximumOf on a valid Y,  or  will always return  a value.   "a  ( empty)  !    ! ::  s a -> s -> , a  ! ::  a =>  s a -> s -> , a  ! ::  Y s a -> s -> , a  ! ::   s a -> s -> , a  ! ::  a =>  = s a -> s -> , a "2Obtain the minimum element (if any) targeted by a  or = Note: minimumOf on a valid Y,  or  will always return  a value.   "a  ( empty)  "    " ::  s a -> s -> , a  " ::  a =>  s a -> s -> , a  " ::  Y s a -> s -> , a  " ::   s a -> s -> , a  " ::  a =>  = s a -> s -> , a #2Obtain the maximum element (if any) targeted by a , =, , Y,  or ( according to a user supplied ordering.   cmp "a  ( empty)  #  cmp   # ::  s a -> (a -> a ->  ) -> s -> , a  # ::  s a -> (a -> a ->  ) -> s -> , a  # ::  Y s a -> (a -> a ->  ) -> s -> , a  # ::   s a -> (a -> a ->  ) -> s -> , a  # ::  = s a -> (a -> a ->  ) -> s -> , a $2Obtain the minimum element (if any) targeted by a , =, , Y  or ( according to a user supplied ordering.   cmp "a  ( empty)  $  cmp   $ ::  s a -> (a -> a ->  ) -> s -> , a  $ ::  s a -> (a -> a ->  ) -> s -> , a  $ ::  Y s a -> (a -> a ->  ) -> s -> , a  $ ::   s a -> (a -> a ->  ) -> s -> , a  $ ::  = s a -> (a -> a ->  ) -> s -> , a %The % function takes a  (or , Y, , 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.   % ::  s a -> (a ->  ) -> s -> , a  % ::  s a -> (a ->  ) -> s -> , a  % ::  Y s a -> (a ->  ) -> s -> , a  % ::   s a -> (a ->  ) -> s -> , a  % ::  = s a -> (a ->  ) -> s -> , a & 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 "a  f   l   "a &     & :: * s a -> (a -> a -> a) -> s -> a  & :: , s a -> (a -> a -> a) -> s -> a  & ::  Y& s a -> (a -> a -> a) -> s -> a  & ::  % s a -> (a -> a -> a) -> s -> a  & ::  = s a -> (a -> a -> a) -> s -> a ' A variant of R that has no base case and thus may only be applied to lenses and structures such < that the lens views at least one element of the structure.    ' l f "a  l f .    "a '     ' :: * s a -> (a -> a -> a) -> s -> a  ' :: , s a -> (a -> a -> a) -> s -> a  ' ::  Y& s a -> (a -> a -> a) -> s -> a  ' ::  % s a -> (a -> a -> a) -> s -> a  ' ::  = s a -> (a -> a -> a) -> s -> a (6Strictly fold right over the elements of a structure.   "a (    ( :: / s a -> (a -> r -> r) -> r -> s -> r  ( :: 1 s a -> (a -> r -> r) -> r -> s -> r  ( ::  Y+ s a -> (a -> r -> r) -> r -> s -> r  ( ::  * s a -> (a -> r -> r) -> r -> s -> r  ( ::  =% s a -> (a -> r -> r) -> r -> s -> r )NFold over the elements of a structure, associating to the left, but strictly.   "a )    ) :: / s a -> (r -> a -> r) -> r -> s -> r  ) :: 1 s a -> (r -> a -> r) -> r -> s -> r  ) ::  Y+ s a -> (r -> a -> r) -> r -> s -> r  ) ::  * s a -> (r -> a -> r) -> r -> s -> r  ) ::  =% s a -> (r -> a -> r) -> r -> s -> r *IMonadic fold over the elements of a structure, associating to the right,  i.e. from right to left.   "a *    * ::  m => 3 s a -> (a -> r -> m r) -> r -> s -> m r  * ::  m => 5 s a -> (a -> r -> m r) -> r -> s -> m r  * ::  m =>  Y/ s a -> (a -> r -> m r) -> r -> s -> m r  * ::  m =>  . s a -> (a -> r -> m r) -> r -> s -> m r  * ::  m =>  =) s a -> (a -> r -> m r) -> r -> s -> m r +HMonadic fold over the elements of a structure, associating to the left,  i.e. from left to right.   "a +    + ::  m => 3 s a -> (r -> a -> m r) -> r -> s -> m r  + ::  m => 5 s a -> (r -> a -> m r) -> r -> s -> m r  + ::  m =>  Y/ s a -> (r -> a -> m r) -> r -> s -> m r  + ::  m =>  . s a -> (r -> a -> m r) -> r -> s -> m r  + ::  m =>  =) s a -> (r -> a -> m r) -> r -> s -> m r ,'Retrieve the first value targeted by a  or = (or  the result  from a  or  ). See also ().     "a , ,This is usually applied in the reader monad (->) s.    , ::  s a -> s -> , a  , ::  s a -> s -> , a  , ::   s a -> s -> , a  , ::  Y s a -> s -> , a  , ::  = s a -> s -> , a LHowever, it may be useful to think of its full generality when working with  a monad transformer stack:   , :: MonadReader s m =>  s a -> m (, a)  , :: MonadReader s m =>  s a -> m (, a)  , :: MonadReader s m =>   s a -> m (, a)  , :: MonadReader s m =>  Y s a -> m (, a)  , :: MonadReader s m =>  = s a -> m (, a) -5Retrieve a function of the first value targeted by a  or  = (or  the result from a  or ). ,This is usually applied in the reader monad (->) s.    - :: # s a -> (a -> r) -> s -> , a  - :: % s a -> (a -> r) -> s -> , a  - ::   s a -> (a -> r) -> s -> , a  - ::  Y s a -> (a -> r) -> s -> , a  - ::  = s a -> (a -> r) -> s -> , a LHowever, it may be useful to think of its full generality when working with  a monad transformer stack:   - :: MonadReader s m => ! s a -> (a -> r) -> m (, r)  - :: MonadReader s m => # s a -> (a -> r) -> m (, r)  - :: MonadReader s m =>   s a -> (a -> r) -> m (, r)  - :: MonadReader s m =>  Y s a -> (a -> r) -> m (, r)  - :: MonadReader s m =>  = s a -> (a -> r) -> m (, r) =      !"#$%&'()*+,-<      !"#$%&'()*+,-<,-      !"#$%()&'*+;      !"#$%&'()*+,-"rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Trustworthy . Provides an 5L that can be used to read, write or delete a member of a set-like container //contains 3 .~ False $ IntSet.fromList [1,2,3,4]fromList [1,2,4]0 type 4 i =  (1 i)1Useful for storage. 4 type 4 i =  (5 i)5Every 5 is a valid  and a valid V. 6Adjust the target of an 5' returning the intermediate result, or ! adjust all of the targets of an V and return a monoidal summary  along with the answer.  l  f "a l 6  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 ( u).   (6) :: 5+ i s t a b -> (i -> a -> b) -> s -> (b, t)  (6) :: Monoid b => V+ i s t a b -> (i -> a -> b) -> s -> (b, t) 7Adjust the target of an 5& returning a supplementary result, or ! adjust all of the targets of an V and return a monoidal summary . of the supplementary results and the answer.  (7) "a    (7) :: / f => 5/ i s t a b -> (i -> a -> f b) -> s -> f t  (7) :: / f => V* i s t a b -> (i -> a -> f b) -> s -> f t ]In particular, it is often useful to think of this function as having one of these even more  restrictive type signatures   (7) :: 55 i s t a b -> (i -> a -> (r, b)) -> s -> (r, t)  (7) :: Monoid r => V0 i s t a b -> (i -> a -> (r, b)) -> s -> (r, t) 8Adjust the target of an 5& returning a supplementary result, or ! adjust all of the targets of an V within the current state, and 9 return a monoidal summary of the supplementary results.  l 8 f "a  (l 7 f)   (8) ::  s m 52 i s s a b -> (i -> a -> (r, b)) -> s -> m r  (8) :: ( s m, Monoid r) => V- i s s a b -> (i -> a -> (r, b)) -> s -> m r 9Adjust the target of an 5' returning the intermediate result, or ! adjust all of the targets of an V within the current state, and 8 return a monoidal summary of the intermediate results.   (9) ::  s m 5( i s s a b -> (i -> a -> b) -> m b  (9) :: ( s m, Monoid b) => V# i s s a b -> (i -> a -> b) -> m b :HThis lens can be used to change the result of a function but only where $ the arguments match the key given. ,let f = (+1) & resultAt 3 .~ 8 in (f 2, f 3)(3,8)./0123456789: ./0123456789: 57689123./:40 ./0123456789: Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy;Ad hoc conversion between "strict" and "lazy" versions of a structure,  such as  or . = type = =  ?>>When you see this as an argument to a function, it expects an ?. ?>Isomorphism families can be composed with other lenses using (-) and 2. @Invert an isomorphism. @ (@ l) "a lAConvert from an  Isomorphism back to any  value. WThis is useful when you need to store an isomorphism as a data type inside a container 6 and later reconstitute it as an overloaded function. See  or 8 for more information on why you might want to do this. B Based on  from Conor McBride's work on Epigram. *This version is generalized to accept any ? , not just a newtype. #au (wrapping Sum) foldMap [1,2,3,4]10C Based on ala' from Conor McBride's work on Epigram. *This version is generalized to accept any ? , not just a newtype. 'For a version you pass the name of the newtype constructor to, see . Mnemonically, the German auf plays a similar role to  la, and the combinator  is B" with an extra function argument. Dauf (wrapping Sum) (foldMapOf both) Prelude.length ("hello","world")10DThe opposite of working over a Setter is working D an Isomorphism.  D "a over - @ D :: ? s t a b -> (s -> t) -> a -> bEBThis isomorphism can be used to convert to or from an instance of .  LT^.from enum097^.enum :: Char'a'GNote: this is only an isomorphism from the numeric range actually used E and it is a bit of a pleasant fiction, since there are questionable   instances for , and  that exist solely for   [1.0 .. 4.0]' sugar and the instances for those and  don't " cover all values in their range. FThis can be used to lift any = into an arbitrary functor. GCComposition with this isomorphism is occasionally useful when your ,  = or ? has a constraint on an unused 3 argument to force that argument to agree with the # type of a used argument and avoid ScopedTypeVariables or other ugliness. HIf v is an element of a type a, and a' is a sans the element v, then non v is an isomorphism from  Maybe a' to a. NKeep in mind this is only a real isomorphism if you treat the domain as being , (a sans v) pThis is practically quite useful when you want to have a map where all the entries should have non-zero values. 4Map.fromList [("hello",1)] & at "hello" . non 0 +~ 2fromList [("hello",3)]4Map.fromList [("hello",1)] & at "hello" . non 0 -~ 1 fromList []0Map.fromList [("hello",1)] ^. at "hello" . non 01%Map.fromList [] ^. at "hello" . non 00KThis combinator is also particularly useful when working with nested maps. e.g.< When you want to create the nested map when it is missing: <Map.empty & at "hello" . non Map.empty . at "world" ?~ "!!!"/fromList [("hello",fromList [("world","!!!")])]Gand when have deleting the last entry from the nested map mean that we 3 should delete its entry from the surrounding one: dfromList [("hello",fromList [("world","!!!")])] & at "hello" . non Map.empty . at "world" .~ Nothing fromList []II a p generalizes H a$ to take any value and a predicate. This function assumes that p a holds True& and generates an isomorphism between , (a | not (p a)) and a FMap.empty & at "hello" . anon Map.empty Map.null . at "world" ?~ "!!!"/fromList [("hello",fromList [("world","!!!")])]nfromList [("hello",fromList [("world","!!!")])] & at "hello" . anon Map.empty Map.null . at "world" .~ Nothing fromList []JBThe canonical isomorphism for currying and uncurrying a function. :t fst^.curriedfst^.curried :: a -> b -> a J =   KBThe canonical isomorphism for uncurrying and currying a function. :t flip (,)^.uncurried'flip (,)^.uncurried :: (b, a) -> (a, b) K =    K = @ J;<=>?@ABCDEFGHIJK;<=>?@ABCDEFGHIJK?>@ABCDFGHIEJK;<=;<=>?@ABCDEFGHIJK Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Safe-InferredL*This is a commonly-used infix alias for a  _ ? M*This is a commonly-used infix alias for a  _ =. N*This is a commonly used infix alias for a  _  >. LMNLMNNMLLMN Rank2Types provisionalEdward Kmett <ekmett@gmail.com>NoneO,Provides access to the 9th field of a tuple P Access the 9th field of a tuple Q+Provide access to the 8th field of a tuple R Access the 8th field of a tuple S+Provide access to the 7th field of a tuple T Access the 7th field of a tuple U.Provides access to the 6th element of a tuple V Access the 6th field of a tuple W,Provides access to the 5th field of a tuple X Access the 5th field of a tuple Y+Provide access to the 4th field of a tuple Z 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 _2 .~ "hello" $ (1,(),3,4)(1,"hello",3,4)(1,2,3,4) & _2 *~ 3 (1,6,3,4)_2 print (1,2)2(1,())     ^ :: (s -> ) -> (a, s) ->   df  ^ :: ( Applicative f, d. t) => (a -> f b) -> t (s, a) -> f (t (s, b))    (df  ^) :: (d t, ! m) => (s -> m) -> t (b, s) -> m _)Provides access to 1st field of a tuple. `@Access the 1st field of a tuple (and possibly change its type).  (1,2)^._11_1 .~ "hello" $ (1,2) ("hello",2)(1,2) & _1 .~ "hello" ("hello",2)_1 putStrLn ("hello","world")hello ((),"world")/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'  ^ k ~(a,b) = (b' -> (a,b')) <$> k b ` k ~(a,b) = (a' -> (a',b)) <$> k a>OPQRSTUVWXYZ[\]^_`      !"#$%&'()*+OPQRSTUVWXYZ[\]^_`_`]^[\YZWXUVSTQROP5OPQRSTUVWXYZ[\]^_`      !"#$%&'()*+ Rank2Types provisionalEdward Kmett <ekmett@gmail.com>Nonea type SimpleReifiedTraversal =  bb A form of f4 that can be stored monomorphically in a container. e type SimpleTraversal =  ffA f can be used directly as a 9 or a  (but not as a ) and provides V the ability to both read and update multiple fields, subject to some relatively weak f laws. UThese have also been known as multilenses, but they have the signature and spirit of   ::  f => f (f a) (f b) a b8and the more evocative name suggests their application. Most of the time the f you will want to use is just , but you can also pass any   or Y as a f, and composition of a f (or  or Y ) with a f (or  or Y)  using (.) forms a valid f. The laws for a Traversal t3 follow from the laws for Traversable as stated in "#The Essence of the Iterator Pattern".    t  "a   3 (t f)  t g "a rs  t (rt  3 f  g) .One consequence of this requirement is that a f1 needs to leave the same number of elements as a  candidate for subsequent fG that it started with. Another testament to the strength of these laws 4 is that the caveat expressed in section 5.5 of the "Essence of the Iterator Pattern" about exotic   instances that E the same entry multiple times was actually already ruled out by the  second law in that same paper! gAMap each element of a structure targeted by a Lens or Traversal, E evaluate these actions from left to right, and collect the results. 0This function is only provided for consistency,  is strictly more general.  g "a This yields the obvious law:   "a g    g :: Y) s t a b -> (a -> f b) -> s -> f t  g :: ( s t a b -> (a -> f b) -> s -> f t  g :: f# s t a b -> (a -> f b) -> s -> f t h A version of g( with the arguments flipped, such that:  h l "a A (g l)   , "a h  0This function is only provided for consistency, A is strictly more general.    h "a A    h :: Y# s t a b -> s -> (a -> f b) -> f t  h :: # s t a b -> s -> (a -> f b) -> f t  h :: f# s t a b -> s -> (a -> f b) -> f t iFEvaluate each action in the structure from left to right, and collect  the results.    - "a i  "a    i l "a g l id "a l id    i :: Y s t (f b) b -> s -> f t  i ::  s t (f b) b -> s -> f t  i :: 0 f => f s t (f b) b -> s -> f t jHMap 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.  . "a j    j :: Y) s t a b -> (a -> m b) -> s -> m t  j :: ( s t a b -> (a -> m b) -> s -> m t  j ::  m => f# s t a b -> (a -> m b) -> s -> m t kk is a flipped version of j$, consistent with the definition of /.    / "a k   k l "a A (j l)     k :: Y) s t a b -> s -> (a -> m b) -> m t  k :: ( s t a b -> s -> (a -> m b) -> m t  k ::  m => f# s t a b -> s -> (a -> m b) -> m t lUSequence the (monadic) effects targeted by a lens in a container from left to right.    0 "a l   l l "a j l id  l l "a 1 . l 2    l :: Y s t (m b) b -> s -> m t  l ::  s t (m b) b -> s -> m t  l ::  m => f s t (m b) b -> s -> m t mThis generalizes  to an arbitrary f. Note: F handles ragged inputs more intelligently, but for non-ragged inputs:   "a m &transposeOf traverse [[1,2,3],[4,5,6]][[1,4],[2,5],[3,6]] Since every  is a f, we can use this as a form of  monadic strength as well: m _2 :: (b, [a] ) -> [(b, a)]nThis generalizes 3 to an arbitrary f.  3 "a n n' accumulates state from right to left.   n :: YA s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)  n :: @ s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)  n :: f; s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) oThis generalizes 4 to an arbitrary f.  4 "a o o' accumulates state from left to right.   o :: YA s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)  o :: @ s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)  o :: f; s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) pThis permits the use of 5 over an arbitrary f or .  5 "a p    p :: Y* s t a a -> (a -> a -> a) -> s -> t  p :: ) s t a a -> (a -> a -> a) -> s -> t  p :: f$ s t a a -> (a -> a -> a) -> s -> t qThis permits the use of 6 over an arbitrary f or .  6 "a q    p :: Y* s t a a -> (a -> a -> a) -> s -> t  p :: ) s t a a -> (a -> a -> a) -> s -> t  p :: f$ s t a a -> (a -> a -> a) -> s -> t rThis f allows you to  the individual stores in a /. ss turns a f into a ( that resembles an early version of the uniplate (or biplate) type. Note:X You should really try to maintain the invariant of the number of children in the list. pAny extras will be lost. If you do not supply enough, then the remainder will come from the original structure. [So technically, this is only a lens if you do not change the number of results it returns. When applied to a  the result is merely a Getter.   s ::  Y s a ->   s [a]  s ::   s a ->   s [a]  s ::  f s a ->   s [a]  s ::  s a -> Getter s [a]  s :: Getter s a -> Getter s [a] tA type-restricted version of s that can only be used with a f. uu turns a f into a uniplate (or biplate ) family.  If you do not need the types of s and t) to be different, it is recommended that  you use s +It is generally safer to traverse with the / rather than use this 2 combinator. However, it is sometimes convenient. !This is unsafe because if you don't supply at least as many b's as you were  given a's, then the reconstruction of t will result in an error! When applied to a  the result is merely a Getter (and becomes safe).   u :: Y s t a b ->  s t [a] [b]  u ::  s t a b ->  s t [a] [b]  u :: f s t a b ->  s t [a] [b]  u ::  s a -> Getter s [a]  u :: Getter s a -> Getter s [a] wThe one-level version of  contextsOfF. This extracts a list of the immediate children according to a given f as editable contexts. Given a context you can use pos to see the values, peekF at what the structure would be like with an edited result, or simply extract the original structure.    propChildren l x =  childrenOf l x 7 8 pos (w l x)  propId l x = 9 (7 x) [extract w | w <- w l x]    w ::   s a -> s -> [2 a a s]  w ::   s a -> s -> [2 a a s]  w ::  f s a -> s -> [2 a a s] xThis converts a f that you know' will target one or more elements to a  . It can ' also be used to transform a non-empty  into a Getter or a non-empty  into an  . The resulting , Getter, or 3 will be partial if the supplied traversal returns  no results.   x :: f s t a a ->  s t a a  x ::  s a -> Getter s a  x ::  m s a ->  m s a yThis converts a f that you know# will target only one element to a . It can also be  used to transform a  into a Getter or a  into an . The resulting , Getter, or 2 will be partial if the Traversal targets nothing  or more than one element.   y :: f s t a b ->  s t a b  y ::  s a -> Getter s a  y ::  m s a ->  m s a z4Traverse both parts of a tuple with matching types. both *~ 10 $ (1,2)(10,20)"over both length ("hello","world")(5,5)("hello","world")^.both "helloworld"{Apply a different f or  to each side of a tuple. .("hello",["world","!!!"])^..beside id traverse["hello","world","!!!"]|Visit the first n targets of a f, , Getter or . =[("hello","world"),("!!!","!!!")]^.. taking 2 (traverse.both)["hello","world"][1..] ^.. taking 3 traverse[1,2,3]+over (taking 5 traverse) succ "hello world" "ifmmp world"}Visit all but the first n targets of a f, , Getter or . $("hello","world") ^? dropping 1 both Just "world"/Dropping works on infinite traversals as well: [1..]^? dropping 1 foldedJust 2~A f2 is completely characterized by its behavior on a /.  Cloning a f! is one way to make sure you aren't given  something weaker, such as a Z and can be H used as a way to pass around traversals that have to be monomorphic in f. !Note: This only accepts a proper f (or ). To clone a   as such, use  Note: It is usually better to c and use d  than to ~2. The former can execute at full speed, while the ( latter needs to round trip through the /. Flet foo l a = (view (cloneTraversal l) a, set (cloneTraversal l) 10 a)foo both ("hello","world")("helloworld",(10,10)) ~ ::  (/ a b) s t a b -> f s t a b&abcdefghijklmno:pqrstuvwxy;<=>?@Az{|}~#/01abcdefghijklmnopqrstuvwxyz{|}~#fghijklmonpqstuvwxyz{|}r~bcdea/01$abcdefghijklmno:pqrstuvwxy;<=>?@Az{|}~"rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com>NoneUseful for storage. Every  is a valid  Z. Fold an  or V/ by mapping indices and values to an arbitrary > with access  to the i.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m+ i a s -> (i -> s -> m) -> a -> m   :: > m => - i a s -> (i -> s -> m) -> a -> m   :: ' i a s -> (i -> s -> m) -> a -> m   :: > m => " i a s -> (i -> s -> m) -> a -> m JRight-associative fold of parts of a structure that are viewed through an  or V with  access to the i.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m5 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: 7 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: 1 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: , i s a -> (i -> a -> r -> r) -> r -> s -> r MLeft-associative fold of the parts of a structure that are viewed through an  or V with  access to the i.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m5 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: 7 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: 1 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: , i s a -> (i -> r -> a -> r) -> r -> s -> r 4Return whether or not any element viewed through an  or V ) satisfy a predicate, with access to the i.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->  5Return whether or not all elements viewed through an  or V ) satisfy a predicate, with access to the i.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->    ::  i s a -> (i -> a ->  ) -> s ->  Traverse the targets of an  or V with access to the i, discarding the results.  When you don' t need access to the index then  C& is more flexible in what it accepts.   C l "a  itraverseOf l      :: / f => m0 i s a -> (i -> a -> f r) -> s -> f ()   :: 0 f => 2 i s a -> (i -> a -> f r) -> s -> f ()   :: / f => , i s a -> (i -> a -> f r) -> s -> f ()   :: 0 f => ' i s a -> (i -> a -> f r) -> s -> f () Traverse the targets of an  or V2 with access to the index, discarding the results  (with the arguments flipped).   "a A   When you don' t need access to the index then  & is more flexible in what it accepts.    l a "a  l a      :: / f => m0 i s a -> s -> (i -> a -> f r) -> f ()   :: 0 f => 2 i s a -> s -> (i -> a -> f r) -> f ()   :: / f => , i s a -> s -> (i -> a -> f r) -> f ()   :: 0 f => ' i s a -> s -> (i -> a -> f r) -> f () *Run monadic actions for each target of an  or V with access to the index,  discarding the results.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a imapMOf l      ::  m => m0 i s a -> (i -> a -> m r) -> s -> m ()   ::  m => 2 i s a -> (i -> a -> m r) -> s -> m ()   ::  m => , i s a -> (i -> a -> m r) -> s -> m ()   ::  m => ' i s a -> (i -> a -> m r) -> s -> m () *Run monadic actions for each target of an  or V with access to the index, 6 discarding the results (with the arguments flipped).   "a A   When you don' t need access to the index then  & is more flexible in what it accepts.    l a "a iforMOf l a      ::  m => m0 i s a -> s -> (i -> a -> m r) -> m ()   ::  m => 2 i s a -> s -> (i -> a -> m r) -> m ()   ::  m => , i s a -> s -> (i -> a -> m r) -> m ()   ::  m => ' i s a -> s -> (i -> a -> m r) -> m () <Concatenate the results of a function of the elements of an  or V  with access to the index.  When you don' t need access to the index then  ' is more flexible in what it accepts.      l "a  l     "a      :: m i s a -> (i -> a -> [r] ) -> s -> [r]   :: " i s a -> (i -> a -> [r] ) -> s -> [r]   ::  i s a -> (i -> a -> [r] ) -> s -> [r]   ::  i s a -> (i -> a -> [r] ) -> s -> [r] The findOf function takes an  or V, 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  & is more flexible in what it accepts.    l "a  l      :: m s a -> (i -> a ->  ) -> s -> , (i, a)   ::  s a -> (i -> a ->  ) -> s -> , (i, a)   ::  s a -> (i -> a ->  ) -> s -> , (i, a)   ::  s a -> (i -> a ->  ) -> s -> , (i, a) Strictly< fold right over the elements of a structure with an index.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      :: m5 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: 7 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: 1 i s a -> (i -> a -> r -> r) -> r -> s -> r   :: , i s a -> (i -> a -> r -> r) -> r -> s -> r 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  & is more flexible in what it accepts.    l "a  l      :: m7 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: 9 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: 3 i s a -> (i -> r -> a -> r) -> r -> s -> r   :: . i s a -> (i -> r -> a -> r) -> r -> s -> r CMonadic fold right over the elements of a structure with an index.  When you don' t need access to the index then  & is more flexible in what it accepts.    l "a  l      ::  m => m7 i s a -> (i -> a -> r -> m r) -> r -> s -> r   ::  m => 9 i s a -> (i -> a -> r -> m r) -> r -> s -> r   ::  m => 3 i s a -> (i -> a -> r -> m r) -> r -> s -> r   ::  m => . i s a -> (i -> a -> r -> m r) -> r -> s -> r 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  & is more flexible in what it accepts.    l "a  l      ::  m => m9 i s a -> (i -> r -> a -> m r) -> r -> s -> r   ::  m => ; i s a -> (i -> r -> a -> m r) -> r -> s -> r   ::  m => 5 i s a -> (i -> r -> a -> m r) -> r -> s -> r   ::  m => 0 i s a -> (i -> r -> a -> m r) -> r -> s -> r .Extract the key-value pairs from a structure.  When you don'1t need access to the indices in the result, then  & is more flexible in what it accepts.    l "a 8 B   l    :: m i s a -> s -> [(i,a)]   ::  i s a -> s -> [(i,a)]   ::  i s a -> s -> [(i,a)]   ::  i s a -> s -> [(i,a)] JTransform an indexed fold into a fold of both the indices and the values.     ::  i s a -> Fold s (i, a)   :: SimpleIndexedLens i s a -> Getter s (i, a)   :: SimpleIndexedTraversal i s a -> Fold s (i, a) All Fold9 operations are safe, and comply with the laws. However: Passing this an IndexedTraversal will still allow many   Traversal9 combinators to type check on the result, but the result K can only be legally traversed by operations that do not edit the indices.     :: IndexedTraversal i s t a b ->  Traversal s t (i, a) (j, b) .Change made to the indices will be discarded. 6Transform an indexed fold into a fold of the indices.    ::  i s a -> Fold s i   :: SimpleIndexedLens i s a -> Getter s i   :: SimpleIndexedTraversal i s a -> Fold s i  Obtain an  by filtering an X, m, or . When passed an V, sadly the result is not a legal V. See filtered for a related counter-example. (Reverse the order of the elements of an  or  V.  This has no effect on an X,  m, or .  Obtain an ! by taking elements from another  , X,  m or V  while a predicate holds.  Obtain an # by dropping elements from another , X, m or V while a predicate holds. CC"rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com>None  type  i =  ( i)Useful for storage.  type  i =  ( i)Every  is a valid Setter The 9" laws are still required to hold. Map with index. /When you do not need access to the index, then mapOf( is more liberal in what it can accept.   l "a  l      :: ) i s t a b -> (i -> a -> b) -> s -> t   :: X+ i s t a b -> (i -> a -> b) -> s -> t   :: V& i s t a b -> (i -> a -> b) -> s -> t %Map with index. This is an alias for . /When you do not need access to the index, then over( is more liberal in what it can accept.   l "a  l      :: ) i s t a b -> (i -> a -> b) -> s -> t   :: X+ i s t a b -> (i -> a -> b) -> s -> t   :: V& i s t a b -> (i -> a -> b) -> s -> t  Build an  from an imap-like function. Your supplied function f is required to satisfy:    f  "a   f g  f h "a f (g  h) Equational reasoning:       "a      "a  Another way to view sets is that it takes a "semantic editor combinator"  and transforms it into a Setter. Adjust every target of an , X or V  with access to the index.  () "a /When you do not need access to the index then ()) is more liberal in what it can accept.  l u f "a l   f   () :: ) i s t a b -> (i -> a -> b) -> s -> t  () :: X+ i s t a b -> (i -> a -> b) -> s -> t  () :: V& i s t a b -> (i -> a -> b) -> s -> t /Adjust every target in the current state of an , X or V  with access to the index. /When you do not need access to the index then ()) is more liberal in what it can accept.  l  f "a l   f   () ::  s m => ' i s s a b -> (i -> a -> b) -> m ()  () ::  s m => X) i s s a b -> (i -> a -> b) -> m ()  () ::  s m => V$ i s t a b -> (i -> a -> b) -> m ()      Rank2Types provisionalEdward Kmett <ekmett@gmail.com>None type  =  A  s t a b is almost a 2. It can be composed on the left of other lenses,  you can use  to promote it to a ), and it provides a minimalist lens-like ^ interface. They can be used in an API where you need to pass around lenses inside containers ! or as monadic results. Unlike a - they can be composed and used directly, but & they are slightly lower performance. A -specific version of () ("hello","world")^#_2"world"A -specific version of p $storing _2 "world" ("hello","there")("hello","world")A -specific version of () !("hello","there") & _2 #~ "world"("hello","world")A -specific version of (u) !("hello","world") & _2 #%~ length ("hello",5)A -specific version of () 6("hello","world") & _2 #%%~ \x -> (length x, x ++ "!")(5,("hello","world!"))A -specific version of () A -specific version of () Modify the target of a  and return the result. "("hello","world") & _2 <#%~ length(5,("hello",5))Modify the target of a  into your monad';s state by a user supplied function and return the result. Modify the target of a > in the current monadic state, returning an auxiliary result. Replace the target of a  and return the new value. "("hello","there") & _2 <#~ "world"("world",("hello","world"))Replace the target of a 8 in the current monadic state, returning the new value.  Rank2Types provisionalEdward Kmett <ekmett@gmail.com> TrustworthyThis class allows us to use ? part of the environment, changing the environment supplied by + many different monad transformers. Unlike G this can change the environment of a deeply nested monad transformer.  Also, unlike ", this can be used with any valid , but cannot be used with a  Traversal or Fold. MRun a monadic action in a larger environment than it was defined in, using a . This acts like D, but can in many cases change the type of the environment as well. mThis is commonly used to lift actions in a simpler Reader monad into a monad with a larger environment type. \This can be used to edit pretty much any monad transformer stack with an environment in it:    ::  s a -> (a -> r) -> s -> r   :: > c => Fold s a -> (a -> r) -> s -> r   :: > w  s t -> D s w st c -> D t w st c   :: (> w, > c) => Fold s t -> D s w st c -> D t w st c  ... This class allows us to use $ in, changing the State supplied by Y many different monad transformers, potentially quite deep in a monad transformer stack. ?Run a monadic action in a larger state than it was defined in,  using a   or  =. FThis 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 = over H multiple values, the actions for each target are executed sequentially ! and the results are aggregated. UThis can be used to edit pretty much any monad transformer stack with a state in it! -flip State.evalState (a,b) $ zoom _1 $ use ida.flip State.execState (a,b) $ zoom _1 $ id .= c(c,b)<flip State.execState [(a,b),(c,d)] $ zoom traverse $ _2 %= f[(a,f b),(c,f d)]<flip State.runState [(a,b),(c,d)] $ zoom traverse $ _2 <%= f((f b <> f d <> mempty,[(a,f b),(c,f d)])/flip State.evalState (a,b) $ zoom both (use id)a <> b    ::  m =>   s t -> E t m a -> E s m a   :: ( m, > c) =>  = s t -> E t m c -> E s m c   ::  m =>   s t -> D r w t m c -> D r w s m c   :: ( m, > c) =>  = s t -> D r w t m c -> D r w s m c   ::  m =>   s t -> F e (D r w t m c) -> F e (D r w s m c)   :: ( m, > c) =>  = s t -> F e (D r w t m c) -> F e (D r w s m c)  ... G  = HIJGKLMNOPQRSTUVHIJGKLMNOPQRSTUV non-portable experimentalEdward Kmett <ekmett@gmail.com>None&The  forms the bulk of a . A  is a recorded path through the f chain of a . This enables us to pull the  back up to the . A B is a linked list of the levels above the current one. The length  of a  is known at compile time. ?This is part of the internal structure of a zipper. You shouldn'$t need to manipulate this directly. This represents the type a  will have when it is fully  back up. This is an alias for '(:>)'". Provided mostly for convenience This is the type of a . It visually resembles a "breadcrumb trail" as Q used in website navigation. Each breadcrumb in the trail represents a level you  can move up to. FThis type operator associates to the left, so you can use a type like    (W,)  W  to represent a zipper from (W,) down to  that has an intermediate  crumb for the W containing the . :You can construct a zipper into *any* data structure with . :t zipper (Just "hello"),zipper (Just "hello") :: Top :> Maybe [Char]3You can repackage up the contents of a zipper with . rezip $ zipper 4242XThe combinators in this module provide lot of things you can do to the zipper while you  have it open. Note that a value of type h  s  a doesn't actually contain a value  of type h  s6 -- as we descend into a level, the previous level is  unpacked and stored in  form. Only one value of type _  _ exists + at any particular time for any particular . This is used to represent the  of the . Every  starts with . e.g.   a is the type of the trivial . This ! views the current target of the . A S that can be used to get to the current location is available as the index of this .  Construct a 5 that can explore anything, and start it at the top. "Return the index into the current f! within the current level of the .   ( l) l = Just''Mnemonically, zippers have a number of " within each level. This is which  you are currently at.  Move the  @, closing the current level and focusing on the parent element. %NB: Attempts to move upward from the  of the  will fail to typecheck. H:t zipper ("hello","world") & downward _1 & fromWithin traverse & upwardEzipper ("hello","world") & downward _1 & fromWithin traverse & upward( :: (Top :> ([Char], [Char])) :> [Char] Jerk the  one  to the  within the current  or f. /Attempts to move past the start of the current f (or trivially, the current )  will return . &isNothing $ zipper "hello" & rightwardTrue?zipper "hello" & fromWithin traverse & rightward <&> view focus'e'Kzipper "hello" & fromWithin traverse & rightward <&> focus .~ 'u' <&> rezip"hullo"Crezip $ zipper (1,2) & fromWithin both & tug rightward & focus .~ 3(1,3) Jerk the   one  within the current  or f. -Attempts to move past the end of the current f (or trivially, the current )  will return . %isNothing $ zipper "hello" & leftwardTrue-Move to the leftmost position of the current f. $This is just a convenient alias for  . Gzipper "hello" & fromWithin traverse & rightmost & focus .~ 'a' & rezip"hella".Move to the rightmost position of the current f. $This is just a convenient alias for  . azipper "hello" & fromWithin traverse & rightmost & focus .~ 'y' & leftmost & focus .~ 'j' & rezip"jelly"This allows you to safely ' tug leftward' or ' tug rightward' on a . This ; will attempt the move, and stay where it was if it fails. KThe more general signature allows its use in other circumstances, however.   f x "a  a (f a)Ofmap rezip $ zipper "hello" & within traverse <&> tug leftward <&> focus .~ 'j'"jello"Pfmap rezip $ zipper "hello" & within traverse <&> tug rightward <&> focus .~ 'u'"hullo"This allows you to safely   or   multiple times on a , O moving multiple steps in a given direction and stopping at the last place you  couldn'Ut move from. This lets you safely move a zipper, because it will stop at either end. Sfmap rezip $ zipper "stale" & within traverse <&> tugs rightward 2 <&> focus .~ 'y'"style"prezip $ zipper "want" & fromWithin traverse & tugs rightward 2 & focus .~ 'r' & tugs leftward 100 & focus .~ 'c'"cart";Move in a direction as far as you can go, then stop there. _This repeatedly applies a function until it returns Nothing, and then returns the last answer. dfmap rezip $ zipper ("hello","world") & downward _1 & within traverse <&> rightmost <&> focus .~ 'a'("hella","world")Xrezip $ zipper ("hello","there") & fromWithin (both.traverse) & rightmost & focus .~ 'm'("hello","therm"))This allows for you to repeatedly pull a 8 in a given direction, failing if it falls off the end. CisNothing $ zipper "hello" & within traverse >>= jerks rightward 10TrueTfmap rezip $ zipper "silly" & within traverse >>= jerks rightward 3 <&> focus .~ 'k'"silky";Returns the number of siblings at the current level in the .   z X 1NB: If the current fE targets an infinite number of elements then this may not terminate.  zipper ("hello","world") & teeth12zipper ("hello","world") & fromWithin both & teeth2.zipper ("hello","world") & downward _1 & teeth1Dzipper ("hello","world") & downward _1 & fromWithin traverse & teeth5;zipper ("hello","world") & fromWithin (_1.traverse) & teeth5=zipper ("hello","world") & fromWithin (both.traverse) & teeth10 Move the $ horizontally to the element in the nth position in the 6 current level, absolutely indexed, starting with the   as 0.  This returns  if the target element doesn' t exist.   n "a   n .  -isNothing $ zipper "not working." & jerkTo 20True Move the $ horizontally to the element in the nth position of the 6 current level, absolutely indexed, starting with the   as 0. %If the element at that position doesn'+t exist, then this will clamp to the range 0 <= n < .   n "a   n .  grezip $ zipper "not working." & fromWithin traverse & tugTo 100 & focus .~ '!' & tugTo 1 & focus .~ 'u'"nut working!"Step down into a  . This is a constrained form of  for when you know 4 there is precisely one target that can never fail.    ::   s a -> (h :> s) -> h :> s :> a   ::  ! s a -> (h :> s) -> h :> s :> a Step down into the  entry of a f.    ::  f( s a -> (h :> s) -> Maybe (h :> s :> a)   ::  - s a -> (h :> s) -> Maybe (h :> s :> a)   ::  . s a -> (h :> s) -> Maybe (h :> s :> a)  Step down into every entry of a f simultaneously. vzipper ("hello","world") & withins both >>= leftward >>= withins traverse >>= rightward <&> focus %~ toUpper <&> rezipI[("hEllo","world"),("heLlo","world"),("helLo","world"),("hellO","world")]    ::  f s a -> (h :> s) -> [h :> s :> a]   ::  % s a -> (h :> s) -> [h :> s :> a]   ::  & s a -> (h :> s) -> [h :> s :> a] Unsafely step down into a f that is assumed to be non-empty. HIf this invariant is not met then this will usually result in an error!     ::  f s a -> (h :> s) -> h :> s :> a   ::  % s a -> (h :> s) -> h :> s :> a   ::  & s a -> (h :> s) -> h :> s :> a =You can reason about this function as if the definition was:   l "a Y -  lMbut it is lazier in such a way that if this invariant is violated, some code I can still succeed if it is lazy enough in the use of the focused value. -Close something back up that you opened as a . Extract the current  from a  as a 2 Save the current path as as a  we can play back later. ?Restore ourselves to a previously recorded position precisely. +If the position does not exist, then fail. GRestore ourselves to a location near our previously recorded position. $When moving left to right through a f0, if this will clamp at each level to the range 0 <= k < teeth, b so the only failures will occur when one of the sequence of downward traversals find no targets. 5Restore ourselves to a previously recorded position. rThis *assumes* that nothing has been done in the meantime to affect the existence of anything on the entire path. NMotions leftward or rightward are clamped, but all traversals included on the  are assumed to be non-empty. ,Violate these assumptions at your own risk! 5This is used to peel off the path information from a 8 for use when saving the current path for later replay. ?Restore ourselves to a previously recorded position precisely. +If the position does not exist, then fail. GRestore ourselves to a location near our previously recorded position. ,When moving leftward to rightward through a f0, if this will clamp at each level to the range 0 <= k < teeth, b so the only failures will occur when one of the sequence of downward traversals find no targets. 5Restore ourselves to a previously recorded position. rThis *assumes* that nothing has been done in the meantime to affect the existence of anything on the entire path. NMotions leftward or rightward are clamped, but all traversals included on the  are assumed to be non-empty. ,Violate these assumptions at your own risk! Reverse a list.  GHC doesn' t optimize  reverse [] into [], so we'll nudge it with our own  reverse function. IThis is relevant when descending into a lens, for example -- we know the + unzipped part of the level will be empty. /Z[--(Z[ non-portable experimentalEdward Kmett <ekmett@gmail.com>None"rank 2 types, MPTCs, TFs, flexible provisionalEdward Kmett <ekmett@gmail.com> Trustworthy type  i =  ( i)Useful for storage. Allows $ of the value at the largest index. & of the element at the largest index. Allows " the value at the smallest index. ) of the element with the smallest index. + provides a lens that can be used to read, ? write or delete the value associated with a key in a map-like  container on an ad hoc basis. !Map.fromList [(1,"hello")] ^.at 1 Just "hello"at 1 ?~ "hello" $ Map.emptyfromList [(1,"hello")]Note: \5-like containers form a reasonable instance, but not Array-like ones, where  you cannot satisfy the  laws. 'This simple indexed traversal lets you $ the value at a given key in a map. JNB:* _setting_ the value of this lens will only set the value in the lens  if it is already present.  k "a  k c  type  i =  ( i)#Every indexed traversal is a valid = or  W. 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!     "a    l =  l   =      :: 5/ i s t a b -> (i -> a -> f b) -> s -> f t   :: * i s t a b -> (i -> a -> f b) -> s -> f t 3Traverse with an index (and the arguments flipped)     l a "a  l a     "a A .      :: 5/ i s t a b -> s -> (i -> a -> f b) -> f t   :: * i s t a b -> s -> (i -> a -> f b) -> f t 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.   l "a  l      ::  m => 5/ i s t a b -> (i -> a -> m b) -> s -> m t   ::  m => * i s t a b -> (i -> a -> m b) -> s -> m t 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 "a  l a     "a A       ::  m => 5/ i s t a b -> s -> (i -> a -> m b) -> m t   ::  m => * i s t a b -> s -> (i -> a -> m b) -> m t  Generalizes 3 to an arbitrary  with access to the index. ' accumulates state from right to left.   l "a  l      :: 5? i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)   :: : i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)  Generalizes 4 to an arbitrary  with access to the index. ' accumulates state from left to right.   l "a  l      :: 5? i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t)   :: : i s t a b -> (i -> s -> a -> (s, b)) -> s -> s -> (s, t) Access the element of an & where the index matches a predicate. Dover (iwhereOf traversed (>0)) reverse ["He","was","stressed","o_O"]["He","saw","desserts","O_o"]    ::  IndexedFold i s a -> (i -> ) ->  IndexedFold i s a   ::  IndexedGetter i s a -> (i -> ) ->  IndexedFold i s a   :: 4 i s a -> (i -> ) ->  i s a   ::  i s a -> (i -> ) ->  i s a   :: SimpleIndexedSetter i s a -> (i -> ) -> SimpleIndexedSetter i s a  Traverse any  container. This is an & that is indexed by ordinal position. This provides a  Traversal) that checks a predicate on a key before ( allowing you to traverse into a value. %This is the trivial empty traversal.   ::  i s s a b  "a   Traverse the nth element  a  Traversal,  or  Y if it exists. 2[[1],[3,4]] & elementOf (traverse.traverse) 1 .~ 5 [[1],[5,4]]*[[1],[3,4]] ^? elementOf (folded.folded) 1Just 3[0..] ^?! elementOf folded 55,take 10 $ elementOf traverse 3 .~ 16 $ [0..][0,1,2,16,4,5,6,7,8,9]    ::   Traversal s a -> Int ->  ? s a   :: Fold s a -> Int ->  IndexedFold ? s a  Traverse the nth element of a  container.  "a  *Traverse (or fold) selected elements of a  Traversal (or Fold3) where their ordinal positions match a predicate.    ::   Traversal s a -> (? -> ) ->  ? s a   :: Fold s a -> (? -> ) ->  IndexedFold ? s a Traverse elements of a > container where their ordinal positions matches a predicate.  "a  #]^_`abcd]^_`abcdTemplateHaskell experimentalEdward Kmett <ekmett@gmail.com> Trustworthy  Provides substitution for types Perform substitution for types HProvides for the extraction of free type variables, and alpha renaming. 4When performing substitution into this traversal you're not allowed 8 to substitute in a name that is bound internally or you' ll violate  the f. laws, when in doubt generate your names with e. Has a f Extract (or modify) the f of something  Traverse free type variables 'Substitute using a map of names in for free type variables  Provides a f. of the types of each field of a constructor. f of the types of the named fields of a constructor. ghijklmnopq  ghijklmnopq Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy#A  with an additional index. 2An instance must satisfy a (modified) form of the  laws:     ( bc) "a bc  3 (  f)    g "a  getCompose    (i -> Compose  3 (f i)  g i)  Traverse an indexed container.  <A container that supports folding with an additional index.  2Fold a container by mapping value to an arbitrary > with access to the index i.  When you don' t need access to the index then r& is more flexible in what it accepts. r "a     HRight-associative fold of an indexed container with access to the index i.  When you don' t need access to the index then s& is more flexible in what it accepts. s "a     GLeft-associative fold of an indexed container with access to the index i.  When you don' t need access to the index then t& is more flexible in what it accepts. t "a    StrictlyF fold right over the elements of a structure with access to the index i.  When you don' t need access to the index then u& is more flexible in what it accepts. u "a   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 )& is more flexible in what it accepts. ) l "a  l  A / with an additional index. .Instances must satisfy a modified form of the / laws:    f   g "a  (i -> f i . g i)   (_ a -> a) "a  Map with access to the index. The  for a .  If you don'!t need access to the index, then mapped& is more flexible in what it accepts. The  of a   container.  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 . aReturn whether or not any element in a container satisfies a predicate, with access to the index i.  When you don' t need access to the index then v& is more flexible in what it accepts. v "a   `Return whether or not all elements in a container satisfy a predicate, with access to the index i.  When you don' t need access to the index then w& is more flexible in what it accepts. w "a   +Traverse elements with access to the index i, discarding the results.  When you don' t need access to the index then x& is more flexible in what it accepts. x l =    +Traverse elements with access to the index i7, discarding the results (with the arguments flipped).   "a A  When you don' t need access to the index then & is more flexible in what it accepts.  a "a  a  *Run monadic actions for each target of an  or  with access to the index,  discarding the results.  When you don' t need access to the index then & is more flexible in what it accepts. y "a $  *Run monadic actions for each target of an  or  with access to the index, 6 discarding the results (with the arguments flipped).   "a A  When you don' t need access to the index then & is more flexible in what it accepts.  l a "a  l a  hConcatenate the results of a function of the elements of an indexed container with access to the index.  When you don' t need access to the index then & is more flexible in what it accepts.    "a  .    "a   xSearches a container with a predicate that is also supplied the index, returning 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 z& is more flexible in what it accepts. z "a   CMonadic fold right over the elements of a structure with an index.  When you don' t need access to the index then {& is more flexible in what it accepts. { "a   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 |& is more flexible in what it accepts. | "a   .Extract the key-value pairs from a structure.  When you don'1t need access to the indices in the result, then & is more flexible in what it accepts.  "a  B   IFold a container with indices returning both the indices and the values. !:Fold a container with indices returning only the indices. "The  of a  container. #3Traverse with an index (and the arguments flipped)   , a "a # a    # "a A   $5Map each element of a structure to a monadic action, Q evaluate these actions from left to right, and collect the results, with access  the index.  When you don't need access to the index .( is more liberal in what it can accept. . "a $  %5Map each element of a structure to a monadic action, Q evaluate these actions from left to right, and collect the results, with access + its position (and the arguments flipped).   / a "a % a    % "a A $ & Generalizes 3 to add access to the index. ' accumulates state from right to left.  "a &  ' Generalizes 4 to add access to the index. ' accumulates state from left to right.  "a '  (PAccess the element of an indexed container where the index matches a predicate. Bover (iwhere (>0)) Prelude.reverse $ ["He","was","stressed","o_O"]["He","saw","desserts","O_o"]}8The position in the sequence is available as the index. ~4The position in the list is available as the index. 5      !"#$%&'(}~!      !"#$%&'(!     ! "#$%&'(.      !"#$%&'(}~ Rank2Types experimentalEdward Kmett <ekmett@gmail.com> Trustworthy )LA generic applicative transformation that maps over the immediate subterms. ) is to  what  is to  This really belongs in  Data.Data. *Nave f using 3. This does not attempt to optimize the traversal. ZThis is primarily useful when the children are immediately obvious, and for benchmarking. +&Find every occurrence of a given type a recursively that doesn' t require # passing through something of type a using , while avoiding traversal . of areas that cannot contain a value of type a. This is , with a more liberal signature. ,Find descendants of type aU non-transitively, while avoiding computation of areas that cannot contain values of  type a using . ,$ is a useful default definition for  -- performs like +, except when s ~ a&, it returns itself and nothing else. . This automatically constructs a  f from an function. (2,4) & upon fst *~ 5(10,4)=There are however, caveats on how this function can be used! nFirst, the user supplied function must access only one field of the specified type. That is to say the target 3 must be a single element that would be visited by  holesOnOf + , CNote: this even permits a number of functions to be used directly. [1,2,3,4] & upon head .~ 0 [0,2,3,4][1,2,3,4] & upon last .~ 5 [1,2,3,5][1,2,3,4] ^? upon tail Just [2,3,4]"" ^? upon tailNothing7Accessing parents on the way down to children is okay: '[1,2,3,4] & upon (tail.tail) .~ [10,20] [1,2,10,20]iSecond, the structure must not contain strict or unboxed fields of the same type that will be visited by  . :: ( s,  a) => (s -> a) ->  [Int] s a/The design of 1 doesn'.t allow it to search inside of values of type a for other values of type a.  /% provides this additional recursion. Like 1, /- trusts the user supplied function more than . using it directly : as the accessor. This enables reading from the resulting * to be considerably faster at the risk of  generating an illegal lens. (upon' (tail.tail) .~ [10,20] $ [1,2,3,4] [1,2,10,20]0 This automatically constructs a  f from a field accessor. The index of the f can be used as an offset into  (h +) or into the list  returned by w +. The design of 0 doesn'.t allow it to search inside of values of type a for other values of type a.  .H provides this additional recursion, but at the expense of performance. 2onceUpon (tail.tail) .~ [10,20] $ [1,2,3,4] -- BAD [1,10,20]/upon (tail.tail) .~ [10,20] $ [1,2,3,4] -- GOOD [1,2,10,20]When in doubt, use . instead. 1This more trusting version of .1 uses your function directly as the getter for a . This means that reading from / is considerably faster than .. 0However, you pay for faster access in two ways:  ( When passed an illegal field accessor, / will give you a  that quietly violates  the laws, unlike ., which will give you a legal f# that avoids modifying the target. m Modifying with the lens is slightly slower, since it has to go back and calculate the index after the fact. 4When given a legal field accessor, the index of the  can be used as an offset into   ( +) or into the list returned by w +. When in doubt, use / instead.  inlineable  .)*+,-./01 )*+,-./01 +*,-./01)$)*+,-./01 Rank2Types provisionalEdward Kmett <ekmett@gmail.com> Trustworthy"2A 2O type is one where we know how to extract its immediate self-similar children.  Example 1:    import Control.Applicative  import Control.Lens  import Control.Plated  import Data.Data  import Data.Data.Lens (,)    data Expr  = Val ?  | Neg Expr  | Add Expr Expr  deriving (,,,,,)    instance 2 Expr where  3 f (Neg e) = Neg  f e  3 f (Add a b) = Add  f a  f b  3 _ a =  a or    instance 2 Expr where  3 = ,  Example 2:    import Control.Applicative  import Control.Lens  import Control.Plated  import Data.Data  import Data.Data.Lens (,)    data Tree a  = Bin (Tree a) (Tree a)  | Tip a  deriving (,,,,,)    instance 2 (Tree a) where  3 f (Bin l r) = Bin  f l  f r  3 _ t =  t or    instance  a => 2 (Tree a) where  3 = , <Note the big distinction between these two implementations. JThe former will only treat children directly in this tree as descendents, I the latter will treat trees contained in the values under the tips also  as descendants! When in doubt, pick a f and just use the various ...Of combinators  rather than pollute 2 with orphan instances! >If you want to find something unplated and non-recursive with -  use the ...OnOf variant with ignored/, though those usecases are much better served < in most cases by using the existing lens combinators! e.g.  - "a @ - ignored. )This same ability to explicitly pass the f in question is why there is no  analogue to uniplate's Biplate. UMoreover, since we can allow custom traversals, we implement reasonable defaults for A polymorphic data types, that only traverse into themselves, and not their  polymorphic arguments. 3f. of the immediate children of this structure. If you'.re using GHC 7.2 or newer and your type has a  instance,  3 will default to ,$ and you can choose to not override  it with your own definition. 4'Extract the immediate descendants of a 2 container. 4 "a  35LRewrite by applying a rule everywhere you can. Ensures that the rule cannot $ be applied anywhere in the result:  propRewrite r x = 9 ( . r) (= (5 r x))Usually A is more appropriate, but 5 can give better 4 compositionality. Given two single transformations f and g , you can  construct a -> f a mplus g a3 which performs both rewrites until a fixed point. 6LRewrite by applying a rule everywhere you can. Ensures that the rule cannot $ be applied anywhere in the result:  propRewriteOf l r x = 9 ( . r) (> l (6 l r x))Usually C is more appropriate, but 6 can give better 4 compositionality. Given two single transformations f and g , you can  construct a -> f a mplus g a3 which performs both rewrites until a fixed point.   6 ::  Y a a -> (a -> , a) -> a -> a  6 ::   a a -> (a -> , a) -> a -> a  6 ::  f a a -> (a -> , a) -> a -> a  6 ::   a a -> (a -> , a) -> a -> a 75Rewrite recursively over part of a larger structure.   7 :: 2 a =>  Y s a -> (a -> , a) -> s -> s  7 :: 2 a =>   s a -> (a -> , a) -> s -> s  7 :: 2 a =>  f s a -> (a -> , a) -> s -> s  7 :: 2 a =>   s a -> (a -> , a) -> s -> s 8NRewrite recursively over part of a larger structure using a specified setter.   8 :: 2 a =>  Y s a ->  Y a a -> (a -> , a) -> s -> s  8 :: 2 a =>   s a ->   a a -> (a -> , a) -> s -> s  8 :: 2 a =>  f s a ->  f a a -> (a -> , a) -> s -> s  8 :: 2 a =>   s a ->   a a -> (a -> , a) -> s -> s 9TRewrite by applying a monadic rule everywhere you can. Ensures that the rule cannot $ be applied anywhere in the result. :RRewrite by applying a monadic rule everywhere you recursing with a user-specified f. A Ensures that the rule cannot be applied anywhere in the result. ;`Rewrite by applying a monadic rule everywhere inside of a structure located by a user-specified f. A Ensures that the rule cannot be applied anywhere in the result. <`Rewrite by applying a monadic rule everywhere inside of a structure located by a user-specified f,  using a user-specified fP for recursion. Ensures that the rule cannot be applied anywhere in the result. =0Retrieve all of the transitive descendants of a 2 container, including itself. >Given a fold that knows how to locate immediate children, retrieve all of the transitive descendants of a node, including itself. > ::  a a -> a -> [a]?Given a  that knows how to find 2O parts of a container retrieve them and all of their descendants, recursively. @Given a ~ that knows how to locate immediate children, retrieve all of the transitive descendants of a node, including itself that lie " in a region indicated by another .  l "a @ l ignoredA<Transform every element in the tree, in a bottom-up manner. 8For example, replacing negative literals with literals:   negLits = A $ x -> case x of  Neg (Lit i) -> Lit ( i)  _ -> x BWTransform every element in the tree in a bottom-up manner over a region indicated by a .   B :: 2 a =>  f s a -> (a -> a) -> s -> s  B :: 2 a =>   s a -> (a -> a) -> s -> s C8Transform every element by recursively applying a given  in a bottom-up manner.   C ::  f a a -> (a -> a) -> a -> a  C ::   a a -> (a -> a) -> a -> a D3Transform every element in a region indicated by a ! by recursively applying another   in a bottom-up manner.   D ::   s a ->  f a a -> (a -> a) -> s -> s  D ::   s a ->   a a -> (a -> a) -> s -> s EITransform every element in the tree, in a bottom-up manner, monadically. FHTransform every element in the tree in a region indicated by a supplied f&, in a bottom-up manner, monadically. F :: ( m, 2 a) =>  f s a -> (a -> m a) -> s -> m sG8Transform every element in a tree using a user supplied f. in a bottom-up manner with a monadic effect. G ::  m => 'Simple f a a -> (a -> m a) -> a -> m aHPTransform every element in a tree that lies in a region indicated by a supplied f, walking with a user supplied f in + a bottom-up manner with a monadic effect. H ::  m =>  f s a ->  f a a -> (a -> m a) -> s -> m sI`Return a list of all of the editable contexts for every location in the structure, recursively.    propUniverse x = = x == 8 pos (I x)  propId x = 9 (7 x) [extract w | w <- I x]  I "a J 3JwReturn a list of all of the editable contexts for every location in the structure, recursively, using a user-specified f to walk each layer.    propUniverse l x = > l x == 8 pos (J l x)  propId l x = 9 (7 x) [extract w | w <- J l x]  J ::  f a a -> a -> [2 a a]K{Return a list of all of the editable contexts for every location in the structure in an areas indicated by a user supplied f, recursively using 3.  K b "a L b 3 K :: 2 a =>  f s a -> s -> [2 a a s]L{Return a list of all of the editable contexts for every location in the structure in an areas indicated by a user supplied f, recursively using  another user-supplied f to walk each layer. L ::  f s a ->  f a a -> s -> [2 a a s]MThe one-level version of contextG. This extracts a list of the immediate children as editable contexts. Given a context you can use pos to see the values, peekF at what the structure would be like with an edited result, or simply extract the original structure.    propChildren x = 4 l x 7 8 pos (M l x)  propId x = 9 (7 x) [extract w | w <- M l x]  M = w 3N An alias for w7, provided for consistency with the other combinators.  N "a w   N ::   s a -> s -> [2 a a s]  N ::   s a -> s -> [2 a a s]  N ::  f s a -> s -> [2 a a s] OIExtract one level of holes from a container in a region specified by one f, using another.  O b l "a w (b  l)   O ::   s a ->   a a -> s -> [2 a a s]  O ::   s a ->   a a -> s -> [2 a a s]  O ::  f s a ->  f a a -> s -> [2 a a s] PKPerform a fold-like computation on each value, technically a paramorphism. P ::  a a -> (a -> [r] -> r) -> a -> rQKPerform a fold-like computation on each value, technically a paramorphism. Q "a P 3R!Fold the immediate children of a 2 container. R z c f =  3 (c  f) zS The original uniplate% combinator, implemented in terms of 2 as a .  S "a s 31The resulting lens is safer to use as it ignores 'over-application'. and deals gracefully with under-application, ( but it is only a proper lens if you don't change the list ! *23456789:;<=>?@ABCDEFGHIJKLMNOPQRS"23456789:;<=>?@ABCDEFGHIJKLMNOPQRS"23456789:;<=>?@ACBDEGFHIJKLMNOQPRS)23456789:;<=>?@ABCDEFGHIJKLMNOPQRS non-portable provisionalEdward Kmett <ekmett@gmail.com> TrustworthyTA  V. UKIf you see this in a signature for a function, the function is expecting a V, ! not some kind of alien invader. VA V l is a 0-or-1 target  Traversal% that can also be turned around with [ to  obtain a 9 in the opposite direction, such that in addition to the  Traversal laws, we also  have  x  [ l ^? l "a  x   l x  1"It may help to think of this as a Y' that can be partial in one direction. Every V is a valid  Traversal. Every Y is a valid V. For example, you might have a  V  Natural allows you to always  go from a Natural to an ,, and provide you with tools to check if an  is  a Natural and/or to edit one if it is.    nat ::  V    nat =    \ i ->  if i  0  then  i  else  ( i) Now we can ask if an  is a Natural. 5^?natJust 5 (-5)^?natNothing!We can update the ones that are: (-3,4) & both.nat *~ 2(-3,8)And we can then convert from a Natural to an . 5 ^. remit nat -- :: Natural5Similarly we can use a V to traverse the left half of an +: Left "hello" & _left %~ lengthLeft 5or to construct an +: 5^.remit _leftLeft 5#such that if you query it with the V), you will get your original input back. 5^.remit _left ^? _leftJust 5&Another interesting way to think of a V! is as the categorical dual of a   a co-8, so to speak. This is what permits the construction of X. WClone a V6 so that you can reuse the same monomorphically typed V for different purposes. See  and cloneTraversal0 for examples of why you might want to do this. XUse a V# as a kind of first-class pattern. X :: V s t a b -> $ (t -> r) (s -> r) (b -> r) (a -> r)YUse a V# to work over part of a structure. Z&Given a pair of prisms, project sums.  Viewing a V9 as a co-lens, this combinator can be seen to be dual to . [Turn a V or Y around to build a . If you have an Y, - is a more powerful version of this function  that will return an Y instead of a mere . 5 ^.remit _leftLeft 5   [ :: V s t a b ->  b t  [ ::  s t a b ->  b t \This can be used to turn an Y or V around and @ a value (or the current environment) through it the other way.  \ "a  - [review _left "mustard"Left "mustard"Usually \ is used in the (->) monad with a  V or Y-, in which case it may be useful to think of < it as having one of these more restricted type signatures:    \ ::   s a -> a -> s  \ ::  V s a -> a -> s [However, when working with a monad transformer stack, it is sometimes useful to be able to \/ the current environment, in which case one of ^ these more slightly more liberal type signatures may be beneficial to think of it as having:   \ ::  a m =>   s a -> m s  \ ::  a m =>  V s a -> m s ]This can be used to turn an Y or V around and @ a value (or the current environment) through it the other way,  applying a function.  ] "a  - [reviews _left isRight "mustard"False%Usually this function is used in the (->) monad with a  V or Y-, in which case it may be useful to think of < it as having one of these more restricted type signatures:    ] ::  " s a -> (s -> r) -> a -> r  ] ::  V s a -> (s -> r) -> a -> r [However, when working with a monad transformer stack, it is sometimes useful to be able to \/ the current environment, in which case one of ^ these more slightly more liberal type signatures may be beneficial to think of it as having:   ] ::  a m =>   s a -> (s -> r) -> m r  ] ::  a m =>  V s a -> (s -> r) -> m r ^This can be used to turn an Y or V around and @ a value (or the current environment) through it the other way.  ^ "a  - [evalState (reuse _left) 5Left 5   ^ ::  a m =>  V s a -> m s  ^ ::  a m =>   s a -> m s _This can be used to turn an Y or V around and - the current state through it the other way,  applying a function.  _ "a  - [*evalState (reuses _left isLeft) (5 :: Int)True   _ ::  a m =>  V s a -> (s -> r) -> m r  _ ::  a m =>   s a -> (s -> r) -> m r `GThis prism provides a traversal for tweaking the left-hand value of an +: over _left (+1) (Left 2)Left 3over _left (+1) (Right 2)Right 2Right 42 ^._left :: String""Left "hello" ^._left"hello">It also can be turned around to obtain the embedding into the  half of an +: 5^.remit _leftLeft 5aHThis prism provides a traversal for tweaking the right-hand value of an +: over _right (+1) (Left 2)Left 2over _right (+1) (Right 2)Right 3Right "hello" ^._right"hello"!Left "hello" ^._right :: [Double][]>It also can be turned around to obtain the embedding into the  half of an +: 5^.remit _rightRight 5 (Unfortunately the instance for  d (+ c) is still missing from base,  so this can' t just be df.) bHThis prism provides a traversal for tweaking the target of the value of  in a ,. over _just (+1) (Just 2)Just 3Unlike traverse this is a V+, and so you can use it to inject as well: 5^.remit _justJust 5TUVWXYZ[\]^_`abTUVWXYZ[\]^_`abVUW[\]^_XYZ`abTTUVWXYZ[\]^_`abRank2, MPTCs, fundeps experimentalEdward Kmett <ekmett@gmail.com>Nonecc6 provides isomorphisms to wrap and unwrap newtypes or " data types with one constructor. dAn isomorphism between s and a and a related one between t and b, such that when a = b, s = t. This is often used via f to aid type inference. eGiven the constructor for a Wrapped type, return a $ deconstructor that is its inverse.  Assuming the Wrapped% instance is legal, these laws hold:    e f  f "a   f  e f "a  op Identity (Identity 4)4op Const (Const "hello")"hello"This is a convenient alias for @ d .Const "hello" & unwrapped %~ length & getConst5f This is a convenient version of d with an argument that' s ignored. GThe argument is used to specify which newtype the user intends to wrap , by using the constructor for that newtype. The user supplied function is ignored, merely its type is used. g This is a convenient version of  with an argument that' s ignored. BThe argument is used to specify which newtype the user intends to remove , by using the constructor for that newtype. The user supplied function is ignored, merely its type is used. h This is a convenient version of d& with two arguments that are ignored. GThese arguments are used to which newtype the user intends to wrap and D should both be the same constructor. This redundancy is necessary ; in order to find the full polymorphic isomorphism family.  The user supplied functions are ignored, merely their types are used. i This is a convenient version of & with two arguments that are ignored. IThese arguments are used to which newtype the user intends to remove and C should both be the same constructor. This redundancy is necessary ; in order to find the full polymorphic isomorphism family.  The user supplied functions are ignored, merely their types are used. jThis combinator is based on ala from Conor McBride's work on Epigram. As with f0, the user supplied function for the newtype is ignored. ala Sum foldMap [1,2,3,4]10ala All foldMap [True,True]Trueala All foldMap [True,False]Falseala Any foldMap [False,False]Falseala Any foldMap [True,False]Trueala Sum foldMap [1,2,3,4]10ala Product foldMap [1,2,3,4]24kThis combinator is based on ala' from Conor McBride's work on Epigram. As with f0, the user supplied function for the newtype is ignored. )alaf Sum foldMap length ["hello","world"]10Use f . unwrapping returns a sorted list. Use f . unwrapping returns a sorted list. Use f . unwrapping returns a sorted list. Use f . unwrapping returns a sorted list. Use f HashSet.fromList'3. Unwrapping returns some permutation of the list. Use f HashMap.fromList'3. Unwrapping returns some permutation of the list. Acdefghijk cdefghijk cdfghiejk@cdefghijk RankNTypes provisionalEdward Kmett <ekmett@gmail.com>NonelGSometimes 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 paths. oRepresentable Functors. A / f is o 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 = q f is a valid choice of x for (nearly) every  o /. @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 o  here. qThe representation of a o / as Lenses rr# is a valid default definition for 3 for a o  functor.  r f m = p  i -> f (m  i) Usage for a o Foo:   instance / Foo where  3 = r ss# is a valid default definition for  and   for a  o functor.  s = p .  Usage for a o Foo:    instance 0 Foo where   = s  ...    instance  Foo where    = s  ... tt$ is a valid default definition for () for a o  functor.  t mf ma = p  i -> mf  i  ma  i Usage for a o Foo:   instance 0 Foo where   = s  () = t uu+ is a valid default default definition for '(>>=)' for a  representable functor.  u m f = p  i -> f (m  i)  i Usage for a o Foo:   instance  Foo where    = s  ( ) = u vA default definition for  for a o /  v wf = p  i -> 3 ( i) wf Usage for a o Foo:   instance  Foo where   = v wA o /- has a fixed shape. This fills each position  in it with a l x A version of p5 that is an isomorphism. Predicativity requires that  we wrap the q as a Key , however. y Map over a o functor with access to the  for the  current position y f m = p  i -> f i (m  i)z Traverse a o) functor with access to the current path { Traverse a o) functor with access to the current path  as a , discarding the result | Traverse a o) functor with access to the current path  and a  (and the arguments flipped) }. over a o) functor with access to the current path  as a  ~. over a o) functor with access to the current path  as a , discarding the result . over a o) functor with access to the current path  as a  (with the arguments flipped)  Fold over a o) functor with access to the current path  as a  , yielding a >  Fold over a o) functor with access to the current path  as a . An  that walks an o / using a l for an index. An  that walks an  o / using a l for an index. An  for a  o /.  NB: The @ requirement on this instance is a consequence of the choice of  as a q, it isn't fundamental. lmnopqrstuvwxyz{|}~  lmnopqrstuvwxyz{|}~opqrstuvlmnwxyz{|}~lmnopqrstuvwxyz{|}~  TemplateHaskell experimentalEdward Kmett <ekmett@gmail.com> Trustworthy+This configuration describes the options we',ll be using to make isomorphisms or lenses. Flags for lens construction Only Generate valid   lenses. HEnables the generation of partial lenses, generating runtime errors for L every constructor that does not have a valid definition for the lens. This L occurs when the constructor lacks the field, or has multiple fields mapped  to the same lens. 5In the situations that a lens would be partial, when  is M used, this flag instead causes traversals to be generated. Only one can be C used, and if neither are, then compile-time errors are generated. )Handle singleton constructors specially. When building a singleton ? (or ') for a record constructor, build both  the ? (or ,) for the record and the one for the field. Use ? for singleton constructors. @Expect a single constructor, single field newtype or data type. 6Create the class if the constructor is simple and the  rule matches. 9Create the instance if the constructor is simple and the  rule matches.  Die if the  fails to match. KIndicate whether or not to supply the signatures for the generated lenses. UDisabling this can be useful if you want to provide a more restricted type signature 1 or if you want to supply hand-written haddocks. SLens to access the convention for naming top level isomorphisms in our lens rules. =Defaults to lowercasing the first letter of the constructor. CLens to access the convention for naming fields in our lens rules. MDefaults to stripping the _ off of the field name, lowercasing the name, and  rejecting the field if it doesn't start with an '_'. JRetrieve options such as the name of the class and method to put in it to . build a class around monomorphic data types. JRetrieve 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 JRules for making fairly simple partial lenses, ignoring the special cases > for isomorphisms and traversals, and not making any classes. ERules for making lenses and traversals that precompose another lens. 1Rules for making an isomorphism from a data type EBuild lenses (and traversals) with a sensible default configuration. ' makeLenses = makeLensesWith lensRules ZMake lenses and traversals for a type, and create a class when the type has no arguments. e.g.   " data Foo = Foo { _fooX, _fooY :: ? }   ''Foo  will create    class HasFoo t where  foo ::   t Foo ! instance HasFoo Foo where foo =   fooX, fooY :: HasFoo t =>   t ?  ) makeClassy = makeLensesWith classyRules 'Make 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 e.g.    newtype List a = List [a]  makeIso ''List  will create    list :: Iso [a] [b] (List a) (List b)  # makeIso = makeLensesWith isoRules >Derive lenses and traversals, specifying explicit pairings of (fieldName, lensName). qIf you map multiple names to the same label, and it is present in the same constructor then this will generate a f. e.g. < makeLensesFor [("_foo", "fooLens"), ("baz", "lbaz")] ''Foo 9 makeLensesFor [("_barX", "bar"), ("_barY", "bar)] ''Bar JDerive lenses and traversals, using a named wrapper class, and specifying  explicit pairings of (fieldName, traversalName). Example usage: K makeClassyFor "HasFoo" "foo" [("_foo", "fooLens"), ("bar", "lbar")] ''Foo *Build lenses with a custom configuration.  ZGiven a set of names, build a map from those names to a set of fresh names based on them. Gets 2[(lens name, (constructor name, field name, type))] from a record constructor 9 0surrounding cxt driven by the data type context data/newtype constructor name args '')   Rank2Types provisionalEdward Kmett <ekmett@gmail.com>None= &/0123cdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'(23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ Control.Exception provisionalEdward Kmett <ekmett@gmail.com>NoneTraverse the strongly typed  contained in  ) where the type of your function matches  the desired .   exception :: ( Applicative f,  a,  b)  => (a -> f b) ->   -> f   !LiberalTypeSynonyms experimentalEdward Kmett <ekmett@gmail.com>None Bitwise ! the target(s) of a  or  _2 .|.~ 6 $ ("hello",3) ("hello",7)   () :: " a =>  s t a a -> a -> s -> t  () :: " a => ? s t a a -> a -> s -> t  () :: " a =>  s t a a -> a -> s -> t  () :: ('Monoid a', " a) => f s t a a -> a -> s -> t Bitwise # the target(s) of a  or  _2 .&.~ 7 $ ("hello",254) ("hello",6)   () :: " a =>  s t a a -> a -> s -> t  () :: " a => ? s t a a -> a -> s -> t  () :: " a =>  s t a a -> a -> s -> t  () :: ('Monoid a', " a) => f s t a a -> a -> s -> t Modify the target(s) of a  ,  or f by computing its bitwise # with another value. *execState (do _1 .&.= 15; _2 .&.= 3) (7,7)(7,3)   () :: ( s m, " a) =>   s a -> a -> m ()  () :: ( s m, " a) =>  ? s a -> a -> m ()  () :: ( s m, " a) =>   s a -> a -> m ()  () :: ( s m, " a) =>  f s a -> a -> m () Modify the target(s) of a  ,  or f by computing its bitwise ! with another value. *execState (do _1 .|.= 15; _2 .|.= 3) (7,7)(15,7)   () :: ( s m, " a) =>   s a -> a -> m ()  () :: ( s m, " a) =>  ? s a -> a -> m ()  () :: ( s m, " a) =>   s a -> a -> m ()  () :: ( s m, " a) =>  f s a -> a -> m () Bitwise ! the target(s) of a  (or f), returning the result 0 (or a monoidal summary of all of the results). _2 <.|.~ 6 $ ("hello",3)(7,("hello",7))   () :: " a => ? s t a a -> a -> s -> (a, t)  () :: " a =>  s t a a -> a -> s -> (a, t)  () :: (" a, ' Monoid a) => f s t a a -> a -> s -> (a, t) Bitwise # the target(s) of a  or f, returning the result 0 (or a monoidal summary of all of the results). _2 <.&.~ 7 $ ("hello",254)(6,("hello",6))   () :: " a => ? s t a a -> a -> s -> (a, t)  () :: " a =>  s t a a -> a -> s -> (a, t)  () :: (" a, ' Monoid a) => f s t a a -> a -> s -> (a, t) Modify the target(s) of a   (or f) by computing its bitwise # with another value, N returning the result (or a monoidal summary of all of the results traversed) runState (_1 <.&.= 15) (31,0) (15,(15,0))   () :: ( s m, " a) =>   s a -> a -> m a  () :: ( s m, " a, Monoid a) =>  f s a -> a -> m a Modify the target(s) of a  , (or f) by computing its bitwise ! with another value, N returning the result (or a monoidal summary of all of the results traversed) runState (_1 <.|.= 7) (28,0) (31,(31,0))   () :: ( s m, " a) =>   s a -> a -> m a  () :: ( s m, " a, Monoid a) =>  f s a -> a -> m a FThis lens can be used to access the value of the nth bit in a number.  n is only a legal  into b if 0 <= n < $ (% :: b)  16^.bitAt 4True 15^.bitAt 4False15 & bitAt 4 .~ True3116 & bitAt 4 .~ False0*Traverse over all bits in a numeric type. ,The bit position is available as the index. toListOf bits (5 :: Word8)/[True,False,True,False,False,False,False,False]If you supply this an !, the result will be an infinite f, which 4 can be productively consumed, but not reassembled.    " non-portable experimentalEdward Kmett <ekmett@gmail.com>None (or ) a list of bytes into a    x = x    x = x  @ Traverse each & in a    = @  d "    (7 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    x = x  @ #Traverse the individual bytes in a  as characters. When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   = @  .     (7 'c') ::  -> # non-portable experimentalEdward Kmett <ekmett@gmail.com>None (or ) a list of bytes into a '   x = x    x = x  @ #Traverse the individual bytes in a '   = @  . "    (7 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    x = x  @ #Traverse the individual bytes in a ' as characters. When writing back to the ' it is assumed that every   lies between '\x00' and '\xff'.   = @  d "    (7 'c') :: ' -> $ non-portable experimentalEdward Kmett <ekmett@gmail.com>NoneTraversals for ByteStrings.  (or () a list of bytes into a strict or lazy    x = x    x = x  @  (or -) a list of characters into a strict or lazy  When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   x = x    x = x  @ Traverse each & in a strict or lazy    = @  d "    (7 0x80) ::  -> 2Traverse the individual bytes in a strict or lazy  as characters. When writing back to the  it is assumed that every   lies between '\x00' and '\xff'.   = @  .     (7 'c') ::  -> ()()% non-portable experimentalEdward Kmett <ekmett@gmail.com>None Access the * of a + number (a :+ b)^._realPartaa :+ b & _realPart *~ 2 a * 2 :+ b  :: / f => (a -> f a) -> + a -> f (+ a) Access the , of a + number (a :+ b)^._imagPartba :+ b & _imagPart *~ 2 a :+ b * 2  :: / f => (a -> f a) -> + a -> f (+ a)This isn't quite a legal lens. Notably the   l ( l b a) = blaw is violated when you set a - value with 0 . and non-zero  / as the /) information is lost, or with a negative .  which flips the / and retains a positive .. So don't do  that! )Otherwise, this is a perfectly cromulent .  Access the . of a + number  (10.0 :+ 20.0) & _magnitude *~ 2 20.0 :+ 40.0This isn't quite a legal lens. Notably the   l ( l b a) = b(law is violated when you set a negative .. This flips the /  and retains a positive .. So don' t do that! )Otherwise, this is a perfectly cromulent .  Setting the . of a zero + number assumes the / is 0.  Access the / of a + number 4(mkPolar 10 (2-pi) & _phase +~ pi & view _phase) "H 2TrueThis isn't quite a legal lens. Notably the   l ( l b a) = blaw is violated when you set a / outside the range (-0, 0]. 7 The phase is always in that range when queried. So don' t do that! )Otherwise, this is a perfectly cromulent .  Access the 1 of a + number *(2.0 :+ 3.0) & _conjugate . _imagPart -~ 1 2.0 :+ 4.02(mkPolar 10.0 2.0 ^. _conjugate . _phase) "H (-2.0)TrueTraverse both the * and the , of a + number. a :+ b & complex .~ cc :+ ca :+ b & complex *~ 2a * 2 :+ b * 2sumOf complex (a :+ b)a + b  :: 0 f => (a -> f b) -> + a -> f (+ b)&portable provisionalEdward Kmett <ekmett@gmail.com>None(Traverse the typed value contained in a 27 where the type required by your function matches that  of the contents of the 2. 'portable provisionalEdward Kmett <ekmett@gmail.com>None IntSet isn't Foldable, but this ) can be used to access the members of an 3. &sumOf members $ setOf folded [1,2,3,4]10This * can be used to change the contents of an 3 by mapping  the elements to new values. Sadly, you can't create a valid f for a Set, because the number of B elements might change but you can manipulate it by reading using  and  reindexing it via . (over setmapped (+1) (fromList [1,2,3,4])fromList [2,3,4,5] Construct an 3 from a , , f,  or ?. 5setOf (folded._2) [("hello",1),("world",2),("!!!",3)]fromList [1,2,3]    ::  s ? -> s -> 3   ::  s ? -> s -> 3   ::  ? s ? -> s -> 3   ::   s ? -> s -> 3   ::  f s ? -> s -> 3 (portable provisionalEdward Kmett <ekmett@gmail.com>NoneA f reading and writing to the  of a  non-empty list. [a,b,c]^? _headJust a[a,b,c] & _head .~ d[d,b,c][a,b,c] & _head %~ f [f a,b,c][] & _head %~ f[][1,2,3]^?!_head1 []^?_headNothing [1,2]^?_headJust 1[] & _head .~ 1[][0] & _head .~ 2[2][0,1] & _head .~ 2[2,1]A f reading and writing to the 4 of a  non-empty list [a,b] & _tail .~ [c,d,e] [a,c,d,e][] & _tail .~ [a,b][]![a,b,c,d,e] & _tail.traverse %~ f[a,f b,f c,f d,f e][1,2] & _tail .~ [3,4,5] [1,3,4,5][] & _tail .~ [1,2][][a,b,c]^?_tail Just [b,c] [1,2]^?!_tail[2]"hello"^._tail"ello" ""^._tail""A f. reading and writing to the last element of a  non-empty list [a,b,c]^?!_lastc []^?_lastNothing[a,b,c] & _last %~ f [a,b,f c] [1,2]^?_lastJust 2[] & _last .~ 1[][0] & _last .~ 2[2][0,1] & _last .~ 2[0,2]A f7 reading and replacing all but the a last element of a  non-empty list [a,b,c,d]^?_init Just [a,b,c] []^?_initNothing[a,b] & _init .~ [c,d,e] [c,d,e,b][] & _init .~ [a,b][][a,b,c,d] & _init.traverse %~ f[f a,f b,f c,d][1,2,3]^?_init Just [1,2][1,2,3,4]^?!_init[1,2,3]"hello"^._init"hell" ""^._init""A V/ stripping a prefix from a list when used as a f, or , prepending that prefix when run backwards: ""preview" ^? strippingPrefix "pre" Just "view"!"review" ^? strippingPrefix "pre"Nothing&"amble"^.remit (strippingPrefix "pre") "preamble") Rank2Types provisionalEdward Kmett <ekmett@gmail.com>None Obtain a  by splitting another ,  >,  or =, according to the given splitting strategy.    :: 5 a ->  i s a ->  [i] s [a]  Obtain a  by splitting another ,  >,  or = on the given delimiter. Equivalent to   6  7.    ::  a => [a] ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or = on any of the given elements. Equivalent to   6  8.    ::  a => [a] ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or =- on elements satisfying the given predicate. Equivalent to   6  9.    :: (a -> ) ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or =0 into chunks terminated by the given delimiter. Equivalent to   6  7.    ::  a => [a] ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or =6 into chunks terminated by any of the given elements. Equivalent to   :  6  8.    ::  a => [a] ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or = into words9, with word boundaries indicated by the given predicate. Equivalent to   ;  6  9.    :: (a -> ) ->  a ->  s [a]  Obtain a  by splitting another ,  >,  or = into lines9, with line boundaries indicated by the given predicate. Equivalent to   :  6  9.    :: (a -> ) ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or = into length-n pieces.    chunkingOf :: ? ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or =% into chunks of the given lengths, .    ::  n => [n] ->  s a ->  s [a]  Obtain a  by splitting another ,  >,  or =+ into chunks of the given lengths. Unlike  , the output = will always be the same length as the first input argument.    ::  n => [n] ->  s a ->  s [a] 0Modify or retrieve the list of delimiters for a 5. )Modify or retrieve the policy for what a 5 to do with delimiters. )Modify or retrieve the policy for what a 5& should about consecutive delimiters. ,Modify or retrieve the policy for whether a 5 should drop an initial blank. ,Modify or retrieve the policy for whether a 5 should drop a final blank.  n<=<=* non-portable experimentalEdward Kmett <ekmett@gmail.com>None A  that can access the nth element of a >. 'Seq.fromList [a,b,c,d] & ordinal 2 %~ ffromList [a,b,f c,d]'Seq.fromList [a,b,c,d] & ordinal 2 .~ efromList [a,b,e,d]#Seq.fromList [a,b,c,d] ^. ordinal 2cDNB:* This is only a legal lens if there is already such an element! A > is isomorphic to a ?  @ m "a m  Seq.fromList [a,b,c] ^. viewLa :< fromList [b,c]Seq.empty ^. viewLEmptyLEmptyL ^. from viewL fromList []!from viewL ^$ a :< fromList [b,c]fromList [a,b,c]A > is isomorphic to a A  B m "a m  Seq.fromList [a,b,c] ^. viewRfromList [a,b] :> cSeq.empty ^. viewREmptyREmptyR ^. from viewR fromList []!from viewR ^$ fromList [a,b] :> cfromList [a,b,c]Traverse the head of a > fromList [a,b,c,d] & _head %~ ffromList [f a,b,c,d]fromList [] ^? _headNothingfromList [a,b,c,d] ^? _headJust aTraverse the tail of a > *fromList [a,b] & _tail .~ fromList [c,d,e]fromList [a,c,d,e]fromList [a,b,c] ^? _tailJust (fromList [b,c])fromList [] ^? _tailNothingTraverse the last element of a > fromList [a,b,c,d] & _last %~ ffromList [a,b,c,f d]fromList [a,b,c,d] ^? _lastJust dfromList [] ^? _lastNothing'Traverse all but the last element of a > fromList [1,2,3] ^? _initJust (fromList [1,2])(fromList [a,b,c,d] & _init.traverse %~ ffromList [f a,f b,f c,d]'fromList [] & _init .~ fromList [a,b,c] fromList []Traverse the first n elements of a > #fromList [a,b,c,d,e] ^.. slicedTo 2[a,b]&fromList [a,b,c,d,e] & slicedTo 2 %~ ffromList [f a,f b,c,d,e]'fromList [a,b,c,d,e] & slicedTo 10 .~ xfromList [x,x,x,x,x]Traverse all but the first n elements of a > %fromList [a,b,c,d,e] ^.. slicedFrom 2[c,d,e](fromList [a,b,c,d,e] & slicedFrom 2 %~ ffromList [a,b,f c,f d,f e])fromList [a,b,c,d,e] & slicedFrom 10 .~ xfromList [a,b,c,d,e](Traverse all the elements numbered from i to j of a > &fromList [a,b,c,d,e] & sliced 1 3 %~ ffromList [a,f b,f c,d,e]    + non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyC (or D ) strict .   C x = x    D x = x  @  -Traverse the individual characters in strict . $anyOf text (=='o') $ "hello"^.packedTrue, non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyPack (or unpack) lazy E.   F x = x    G x = x  @  (Traverse the individual characters in a E. $ anyOf text (=='c') :: Text -> Bool - non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyTraversals for strict or lazy  F (or G) strict or lazy .   F x = x    G x = x  @  5Traverse the individual characters in strict or lazy . HIHI.MTPCs provisionalEdward Kmett <ekmett@gmail.com>NoneA  that focuses on the root of a J. view root $ Node 42 []42A 3 returning the direct descendants of the root of a J   "a K/ Rank2Types experimentalEdward Kmett <ekmett@gmail.com> TrustworthyA  f for working with a L of a  value. A  f for working with a M of a  value. 0 non-portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy "A lens reading and writing to the N of a  non-empty O #Attempting to read or write to the N of an empty O will result in an . Vector.fromList [1,2,3]^._head1A  reading and writing to the P element of a  non-empty O #Attempting to read or write to the P element of an empty O will result in an . Vector.fromList [1,2]^._last2"A lens reading and writing to the Q of a  non-empty O #Attempting to read or write to the Q of an empty O will result in an . 8_tail .~ Vector.fromList [3,4,5] $ Vector.fromList [1,2]fromList [1,3,4,5]A % reading and replacing all but the a P element of a  non-empty O +Attempting to read or write to all but the P element of an empty O will result in an .  Vector.fromList [1,2,3,4]^._initfromList [1,2,3] sliced i n provides a lens that edits the n elements starting at index i from a lens. KThis is only a valid lens if you do not change the length of the resulting O. QAttempting to return a longer or shorter vector will result in violations of the  laws.  Similar to , but returning a O. Convert a list to a O (or back)  Convert a O9 to a version with all the elements in the reverse order  Convert a O to a version that doesn't retain any extra memory. $This is a more efficient version of  that works for any O.  ordinal n is only a valid  into a O with R at least n + 1. This f= will ignore any duplicates in the supplied list of indices. >toListOf (ordinals [1,3,2,5,9,10]) $ Vector.fromList [2,4..40][4,8,6,12,20,22] i starting index n length    1 non-portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy"A lens reading and writing to the S of a  non-empty T #Attempting to read or write to the S of an empty T will result in an . Vector.fromList [1,2,3]^._head1A  reading and writing to the U element of a  non-empty T #Attempting to read or write to the U element of an empty T will result in an . Vector.fromList [1,2]^._last2"A lens reading and writing to the V of a  non-empty T #Attempting to read or write to the V of an empty T will result in an . 8_tail .~ Vector.fromList [3,4,5] $ Vector.fromList [1,2]fromList [1,3,4,5]A % reading and replacing all but the a U element of a  non-empty T +Attempting to read or write to all but the U element of an empty T will result in an .  Vector.fromList [1,2,3,4]^._initfromList [1,2,3] sliced i n provides a lens that edits the n elements starting at index i from a lens. KThis is only a valid lens if you do not change the length of the resulting T. QAttempting to return a longer or shorter vector will result in violations of the  laws.   Similar to , but returning a T.  Convert a list to a T (or back)   Convert a T to a finite W (or back)   Convert a T to a finite W from right to left (or back)   Convert a TG back and forth to an initializer that when run produces a copy of the T.  Convert a T to a version that doesn't retain any extra memory.  Convert a T9 to a version with all the elements in the reverse order $This is a more efficient version of  that works for any T.  ordinal n is only a valid  into a T with X at least n + 1. This f= will ignore any duplicates in the supplied list of indices. >toListOf (ordinals [1,3,2,5,9,10]) $ Vector.fromList [2,4..40][4,8,6,12,20,22]i starting index n length                     2GHC experimentalEdward Kmett <ekmett@gmail.com>NoneUsed to traverse Y data by uniplate. ;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 Y f that visits every occurrence  of something  anywhere in a container. BallOf tinplate (=="Hello") (1::Int,2::Double,(),"Hello",["Hello"])True:mapMOf_ tinplate putStrLn ("hello",[(2 :: Int, "world!")])helloworld! Z[\]^_`a Z[\]^_`a3&MPTCs, Rank2Types, LiberalTypeSynonyms provisionalEdward Kmett <ekmett@gmail.com>NoneAccess an element of an array. <Note: The indexed element is assumed to exist in the target b.    arr c i "a arr   i  arr d [(i,e)] "a  i  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 b from an old array by E applying a function to each of the indices to look it up in the old b.  This is a  contravariant .   e "a  .    "a  . e   ( b) f arr c i "a arr c f i  f ( ( b) f arr) "a b An  of the elements of an b , using the 5 index into the array as the index of the traversal. g "a  4 Rank2Types experimentalEdward Kmett <ekmett@gmail.com>None (Modify the path by adding another path. #both </>~ "bin" $ ("hello","world")("hello/bin","world/bin")   () ::  s a h h -> h -> s -> a  () :: ? s a h h -> h -> s -> a  () ::  s a h h -> h -> s -> a  () :: f s a h h -> h -> s -> a Modify the target(s) of a  , ?,  or f by adding a path. -execState (both </>= "bin") ("hello","world")("hello/bin","world/bin")   () ::  s m =>   s h -> h -> m ()  () ::  s m =>  ? s h -> h -> m ()  () ::  s m =>   s h -> h -> m ()  () ::  s m =>  f s h -> h -> m () +Add a path onto the end of the target of a  and return the result 3When you do not need the result of the operation, () is more flexible. +Add a path 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. %Modify the path by adding extension. #both <.>~ "txt" $ ("hello","world")("hello.txt","world.txt")   () ::  s a h h -> W -> s -> a  () :: ? s a h h -> W -> s -> a  () ::  s a h h -> W -> s -> a  () :: f s a h h -> W -> s -> a Modify the target(s) of a  , ?,  or f by adding an extension. -execState (both <.>= "txt") ("hello","world")("hello.txt","world.txt")   () ::  s m =>   s h -> W -> m ()  () ::  s m =>  ? s h -> W -> m ()  () ::  s m =>   s h -> W -> m ()  () ::  s m =>  f s h -> W -> m () 1Add an extension onto the end of the target of a  and return the result "_1 <<.>~ "txt" $ ("hello","world")#("hello.txt",("hello.txt","world"))3When you do not need the result of the operation, () is more flexible.  1Add an extension onto the end of the target of a  into  your monad's state and return the result. -evalState (_1 <<.>= "txt") $("hello","world") "hello.txt"3When you do not need the result of the operation, () is more flexible. !A ) for reading and writing to the basename (basename .~ "filename" $ "path/name.png""path/filename.png""A * for reading and writing to the directory !"long/path/name.txt" ^. directory "long/path"#A * for reading and writing to the extension %extension .~ ".png" $ "path/name.txt""path/name.png"$A . for reading and writing to the full filename (filename .~ "name.txt" $ "path/name.png""path/name.txt"  !"#$  !"#$  !"#$  !"#$5portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy%Evaluate the targets of a  or f into a data structure  according to the given i.    j = %  =   % =     % ::   s a -> i a -> i s  % ::  f s a -> i a -> i s  % :: (a -> k a) -> s -> k s) -> i a -> i s &Evaluate the targets of a  or f according into a % data structure according to a given i in parallel.  l = &    & ::   s a -> i a -> i s  & ::  f s a -> i a -> i s  & :: ((a -> k a) -> s -> k s) -> i a -> i s ' Transform a , , ,  or f to 3 first evaluates its argument according to a given i before proceeding.   ' m  ::  t => i a -> i [a] ( Transform a , , ,  or f to , evaluate its argument according to a given i in parallel with evaluating.   ( m  ::  t => i a -> i [a] %&'(%&'(%&'(%&'(6portable provisionalEdward Kmett <ekmett@gmail.com>None)$Evaluate the elements targeted by a , f, ?,   or " according to the given strategy. n = ) ))))oddfF;Y7         !!"#$%&'()*+,-./01234[56789:;<=>?@ABCDEF9GHIpJuKLMvxwyz{|}~NOPQRSTUVWXq<YZ[o\]^_`abc d e d e f g h i j k l m n o p q _ > r s t u v w x y z { | } ~                           Z  g       8         C               @ A     XY=:W\      !"#$%&'()*+,-.GH/0/112345467879:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abVcdefghijklmnopqrstuvwxyz{|}~7      !!!!!!! !!!"!#"$"%"&"'#$#%#&#'$($$$&$%$'%)%*%+%,%-%.%/&0'1'd'e(2(3(4(5(6)7)8)9):);)<)=)>)?)@)A)B)C)D)E)F*G*H*I*2*3*4*5*J*K*L+M+N,M,N-O-M-N.P.Q/R/S020403050L0T0U0V0W0G0X121413151L1T1U1Y1Z1[1W1V1G1X2\2]2^23_3`3a4b4c4d4e4f4g4h4i4j4k4l4m5n5o5p5q6rstuvwxsyzbc{|}~}s{{UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU{{y{]{w        h }!"#$%&'(#$)#$*#$+,-.-/-0123-4-5678}9:];<=>?-@-ABCD-E FGwHIJKLMwN-wO P{QRSTU`aVWX2YZ[\]^_`_abcdefghijklmnopqrstuvwxyz{|}~ddddd}}dd-- {-_PzRzTzJ{ wBP]     }  u u!"#$%&%'(%)*%+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]{^{_`abcdefghijklmnopqrstutvwxwywzw{I|}~VX$$kklkkkk k(-))UUUaUU--A@A@22222222lens-3.7Control.Lens.TraversalControl.Lens.ClassesControl.Lens.InternalControl.Lens.IndexedControl.Lens.IndexedGetterControl.Lens.ActionControl.Lens.SetterControl.Lens.Getter Data.Set.LensData.HashSet.LensControl.Lens.CombinatorsControl.Lens.TypeControl.Lens.FoldControl.Lens.IndexedLensControl.Lens.IsoControl.Lens.SimpleControl.Lens.TupleControl.Lens.IndexedFoldControl.Lens.IndexedSetterControl.Lens.LoupeControl.Lens.ZoomControl.Lens.Internal.ZipperControl.Lens.IndexedTraversalLanguage.Haskell.TH.LensControl.Lens.WithIndexData.Data.LensControl.Lens.PlatedControl.Lens.PrismControl.Lens.WrappedControl.Lens.RepresentableControl.Lens.THControl.Exception.LensData.Bits.LensData.ByteString.Strict.LensData.ByteString.Lazy.LensData.ByteString.LensData.Complex.LensData.Dynamic.LensData.IntSet.LensData.List.LensData.List.Split.LensData.Sequence.LensData.Text.Strict.LensData.Text.Lazy.LensData.Text.LensData.Tree.LensData.Typeable.LensData.Vector.LensData.Vector.Generic.LensGHC.Generics.LensData.Array.LensSystem.FilePath.Lens Control.Parallel.Strategies.LensControl.Seq.LensPrism backwardsSettertakingSettableGetter TraversalLensclone maximumOf minimumOfmapM_ traverseOf_Control.Monad.Trans.State.LazyStateindexedZoomzoomControl.Monad.ErrorErrorTControl.Monad.Trans.MaybeMaybeTControl.Monad.Trans.ListListTControl.Monad.WriterWriterTControl.Monad.RWSRWSTControl.Monad.StateStateT!Control.Lens.Internal.CombinatorsIndexedTraversal IndexedFold IndexedLensIsoFold IndexedGetter ifoldMapOf Control.MonadjoinSimpleData.Text.InternalTextData.Functor.IdentityIdentityData.Traversable fmapDefaulttraversefolded Data.Functor<$ imaginary Data.ComplexComplex traverseHeadControl.Lens.LensviewsetGettingData.Functor.Compose getComposeCompose%~+~-~*~//~^~^^~**~||~&&~%=+=-=*=//=**=^^=||=&&=Preludeunfoldr ibackwardsControl.Lens.Isomorphicfrom Data.FoldablefoldMapfoldfoldrfoldltoListandoranyallproductsum traverseOf traverse_Data.Either.Lens traverseLeftforOffor_forM_ sequence_ maximumByfoldr1foldl1Offoldl1foldr'foldl'foldrMfoldlM%@~cloneTraversalalaalafanyOf Traversable foldMapOf Data.MonoidMonoid Data.List transpose MonadicFoldActionSimpleIndexedLensSimpleIndexedTraversalfoldrOffoldlOfallOfforOf_mapMOf_forMOf_ concatMapOffindOffoldrOf'foldlOf'foldrMOffoldlMOftoListOf IndexedSettermapOfover^..~.=Control.Monad.Reader.ClasslocalControl.Lens.ZippermapMOfforMOf mapAccumROf mapAccumLOfmap mapAccumRControl.Platedplate Data.Just isNothinglengthOfNumeric.NaturalNaturalData.Distributive distribute Distributive Control.LensData.ByteStringpackunpackData.ByteString.Char8Data.ByteString.LazyData.ByteString.Lazy.Char8base Indexable Prismaticprism Isomorphiciso untainted untainted#tainted# Effective effective ineffectiveGettablecoercenoEffectIndexed withIndexIsoidPrismoidCoBCoABazaarT runBazaarTMutator runMutatorFolding getFoldingAccessor runAccessor EffectRWS getEffectRWSEffect getEffectBazaar runBazaarContextMaxNoMaxMinNoMin Sequenced getSequenced Traversed getTraversedIndexing runIndexing FocusingErr unfocusingErrErrgetErr FocusingMay unfocusingMayMaygetMay FocusingOn unfocusingOn FocusingPlusunfocusingPlus FocusingWithunfocusingWithFocusing unfocusinggetMingetMaxbazaarduplicateBazaarsellbazaarTduplicateBazaarTsellT<..> reindexed<.>icomposeindexingReifiedIndexedGetterReifyIndexedGetterreflectIndexedGetterIndexedGettingiviewiviewsiuseiusesActingperformperforms^!actactsliftActSimpleReifiedSetter ReifiedSetter ReifySetter reflectSetter SimpleSetting SimpleSetterSettingmappedliftedsetsset'?~<.~~<>= ReifiedGetter ReifyGetter reflectGetter&^&toviews^$useusesuse'uses'view'views' setmappedsetOf<$!><$!<&>SimpleReifiedLens ReifiedLens ReifyLens reflectLensSimpleOverloaded OverloadedLensLikeSimpleLensLike SimpleLenslens%%~%%=insidechoosingchosen alongsidelocus cloneLens<%~<+~<-~<*~~<<>= ReifiedFold ReifyFold reflectFoldfoldingrepeated replicatedcycledunfoldediteratedfiltered takingWhile droppingWhilefoldOf^..andOforOf productOfsumOf sequenceAOf_ sequenceOf_asumOfmsumOfelemOf notElemOfconcatOfheadOf^?^?!firstOflastOfnullOf notNullOf maximumByOf minimumByOffoldr1OfpreviewpreviewsContainscontainsSimpleReifiedIndexedLensReifiedIndexedLensReifyIndexedLensreflectIndexedLens<%@~%%@~%%@=<%@=resultAtStrictstrict SimpleIsoAnIsocloneIsoauaufunderenummappingsimplenonanoncurried uncurried:<->:=>:->Field9_9Field8_8Field7_7Field6_6Field5_5Field4_4Field3_3Field2_2Field1_1SimpleReifiedTraversalReifiedTraversalReifyTraversalreflectTraversalSimpleTraversal sequenceAOf sequenceOf transposeOfscanr1Ofscanl1OflocipartsOfpartsOf' unsafePartsOfunsafePartsOf'holesOfsingularunsafeSingularbothbesidedroppingReifiedIndexedFoldReifyIndexedFoldreflectIndexedFoldifoldrOfifoldlOfianyOfiallOf itraverseOf_iforOf_imapMOf_iforMOf_ iconcatMapOfifindOf ifoldrOf' ifoldlOf' ifoldrMOf ifoldlMOf itoListOf withIndicesOf indicesOf ifiltering itakingWhileidroppingWhileSimpleReifiedIndexedSetterReifiedIndexedSetterReifyIndexedSetterreflectIndexedSetterSimpleIndexedSetterimapOfioverisets%@= SimpleLoupeLoupe^#storing#~#%~#%%~#=#%=<#%~<#%=#%%=<#~<#=MagnifymagnifyTrackForkTapeZippingrecoilCoilSnocZippedZipper:>Topfocuszippertoothupward rightwardleftwardleftmost rightmosttugtugsfarthestjerksteethjerkTotugTodownwardwithinwithins fromWithinrezipfocusedContextsaveTape restoreTaperestoreNearTapeunsafelyRestoreTapepeel restoreTrackrestoreNearTrackunsafelyRestoreTrack reverseListSimpleReifiedIndexedTraversalReifiedIndexedTraversalReifyIndexedTraversalreflectIndexedTraversal TraverseMax traverseMax TraverseMin traverseMinAtat_at itraverseOfiforOfimapMOfiforMOf imapAccumROf imapAccumLOfiwhereOf traversedvalueignored elementOfelement elementsOfelements SubstType substType HasTypeVars typeVarsExHasNamenametypeVars substTypeVars conFieldsconNamedFieldsTraversableWithIndex itraverseFoldableWithIndexifoldMapifoldrifoldlifoldr'ifoldl'FunctorWithIndeximapimappedifoldedifoldingianyiall itraverse_ifor_imapM_iforM_ iconcatMapifindifoldrMifoldlMitoList withIndicesindices itraversediforimapMiforM imapAccumR imapAccumLiwhere gtraversetinplatetemplateuniplatebiplateuponupon'onceUpon onceUpon'Platedchildrenrewrite rewriteOf rewriteOn rewriteOnOfrewriteM rewriteMOf rewriteMOn rewriteMOnOfuniverse universeOf universeOn universeOnOf transform transformOn transformOf transformOnOf transformM transformMOn transformMOftransformMOnOfcontexts contextsOf contextsOn contextsOnOfholesholesOn holesOnOfparaOfpara composOpFoldparts SimplePrismAPrism clonePrismoutsideasidewithoutremitreviewreviewsreusereuses_left_right_justWrappedwrappedopwrapping unwrapping wrappings unwrappingsPathwalk RepresentablerepRepfmapReppureRepapRepbindRep distributeReppaths tabulatedrmap rtraverse rtraverse_rforrmapMrmapM_rforMrfoldMaprfoldrrmappedrfolded rtraversed LensRulesLensFlagGenerateSignatures ClassRequiredCreateInstance CreateClassSingletonRequiredHandleSingletons SingletonIsoSingletonAndFieldBuildTraversals PartialLenses SimpleLenses simpleLenses partialLensesbuildTraversalshandleSingletonssingletonAndField singletonIsosingletonRequired createClasscreateInstance classRequiredgenerateSignatureslensIso lensField lensClass lensFlags defaultRules lensRules classyRulesisoRules makeLenses makeClassymakeIso makeLensesFor makeClassyFormakeLensesWith exception.|.~.&.~.&.=.|.=<.|.~<.&.~<.&.=<.|.=bitAtbits packedBytesbytes packedCharschars IsByteString _realPart _imagPart_polar _magnitude_phase _conjugatecomplexdynamicmembers_head_tail_last_initstrippingPrefix splitting splittingOnsplittingOneOf splittingWhenendingBy endingByOneOf wordingByliningBychunkingsplittingPlacessplittingPlacesBlanks delimiters delimiting condensingkeepInitialBlankskeepFinalBlanksordinalviewLviewRslicedTo slicedFromslicedpackedtextIsTextrootbranches_cast_gcast toVectorOfvectorreversedforcedordinalsasStream asStreamRcloned GTraversalgenericgeneric1ixixmapped_array~=<~<=<.>~<.>=<<.>~<<.>=basename directory extensionfilenameevalOfparOfafter throughoutseqOfControl.CategoryCategory Data.EitherEither Data.MaybeMaybe.transformers-0.3.0.0GHC.BaseFunctorControl.Applicative ApplicativeConstidfmap$fSettableBackwards$fSettableIdentity$fIndexablei(->)$fPrismatic(->)$fIsomorphic(->)$fSettableCompose$fEffectivemDualBackwards$fGettableCompose$fGettableBackwards$fGettableConstghc-prim GHC.TypesIntcomonad-3.0.0.2Control.ComonadComonadflip$fIndexableiIndexedArgOf$fIsomorphicIsoid$fCategoryIsoid$fPrismaticPrismoid$fIsomorphicPrismoid$fCategoryPrismoid$fGettableBazaarT$fComonadBazaarT$fApplicativeBazaarT$fFunctorBazaarT$fSettableMutator$fApplicativeMutator$fFunctorMutator$fMonoidFolding$fEffectiveIdentityrAccessor$fGettableAccessor$fApplicativeAccessor$fFunctorAccessor$fApplicativeEffectRWS$fGettableEffectRWS$fFunctorEffectRWS$fEffectivemrEffect$fGettableEffect$fApplicativeEffect$fMonoidEffect$fFunctorEffect$fComonadApplyBazaar$fComonadBazaar$fApplicativeBazaar$fFunctorBazaar$fComonadStoreaContext$fComonadContext$fFunctorContext $fMonoidMax $fMonoidMin$fMonoidSequenced$fMonoidTraversed$fGettableIndexing$fApplicativeIndexing$fFunctorIndexing$fApplicativeFocusingErr$fFunctorFocusingErr $fMonoidErr$fApplicativeFocusingMay$fFunctorFocusingMay $fMonoidMay$fApplicativeFocusingOn$fFunctorFocusingOn$fApplicativeFocusingPlus$fFunctorFocusingPlus$fApplicativeFocusingWith$fFunctorFocusingWith$fApplicativeFocusing$fFunctorFocusingconst# getConst#zipList# getZipList# wrapMonad# unwrapMonad#last#getLast#first# getFirst#product# getProduct#sum#getSum#any#getAny#all#getAll#dual#getDual#endo#appEndo#may#getMay#folding# getFolding#effect# getEffect# effectRWS# getEffectRWS# accessor# runAccessor#err#getErr# traversed# getTraversed# sequenced# getSequenced# focusing# unfocusing# focusingWith#unfocusingWith# focusingPlus#unfocusingPlus# focusingOn# unfocusingOn# focusingMay#unfocusingMay# focusingErr#unfocusingErr#mutator# runMutator# backwards# forwards#MonadCharliftM$JustGHC.NumNumGHC.Real FractionalIntegral GHC.FloatFloating GHC.Classes||Bool&& mtl-2.1.2Control.Monad.State.Class MonadStatemappend MonadReadercontainers-0.5.0.0 Data.Set.BaseSetOrdunordered-containers-0.2.2.1 Data.HashSetHashSethashable-1.1.2.5 Data.HashableHashableEq<$>purestatecomonads-fd-3.0Control.Comonad.Store.Classposcomonad-transformers-3.0Control.Comonad.Trans.StoreStoreseek ComonadStoreseeksFoldableGHC.Listrepeat replicateiterateevenGHC.Enumsucc takeWhile dropWhileTrue sequenceA_asum Alternativemsum MonadPluselemnotElem concatMapconcatlengthheadFirstLastFalsenullnotmaximum fromMaybeGHC.ErrerrorminimumOrdering minimumByNothing listToMaybeskipconst$fContainskHashSet$fContainskSet$fContainsIntIntSet text-0.11.2.3bytestring-0.10.0.0Data.ByteString.Internal ByteStringEnumDoubleFloat integer-gmpGHC.Integer.TypeInteger Data.Tuplecurryuncurry$fStrictTextTextTextText0$fStrictByteStringByteStringByteStringByteString$fField2(,)(,)bb'$fField1(,)(,)aa'$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'$fField1(,,,,,,,,)(,,,,,,,,)aa'$fField1(,,,,,,,)(,,,,,,,)aa'$fField1(,,,,,,)(,,,,,,)aa'$fField1(,,,,,)(,,,,,)aa'$fField1(,,,,)(,,,,)aa'$fField1(,,,)(,,,)aa'$fField1(,,)(,,)aa'for sequenceAmapMforMsequence unwrapMonad WrapMonad mapAccumLscanr1scanl1==swapinsouts unsafeOutsinsToutsT unsafeOutsTunconsWithDefaultfstControl.Monad.Trans.RWS.Strict Control.Monad.Trans.State.StrictControl.Monad.Trans.Error$fMagnify(->)(->)Accessorba$fMagnifyIdentityTIdentityTkba$fMagnifyRWSTRWSTEffectRWSba$fMagnifyRWSTRWSTEffectRWSba0$fMagnifyReaderTReaderTEffectba$fZoomErrorTErrorTFocusingErrst$fZoomMaybeTMaybeTFocusingMayst$fZoomListTListTFocusingOnst"$fZoomWriterTWriterTFocusingPlusst#$fZoomWriterTWriterTFocusingPlusst0$fZoomRWSTRWSTFocusingWithst$fZoomRWSTRWSTFocusingWithst0$fZoomIdentityTIdentityTkst$fZoomReaderTReaderTkst$fZoomStateTStateTFocusingst$fZoomStateTStateTFocusingst0String>=fromJust $fZipping:>a $fZippingTopa Data.Map.BaseMap$fTraverseMaxkMap$fTraverseMaxIntIntMap$fTraverseMinkMap$fTraverseMinIntIntMap $fAtkHashMap$fAtkMap $fAtIntIntMaptemplate-haskellLanguage.Haskell.TH.SyntaxnewNameName$fSubstTypePred $fSubstType[]$fSubstTypeType$fHasTypeVars[]$fHasTypeVarsPred$fHasTypeVarsType$fHasTypeVarsName$fHasTypeVarsTyVarBndr $fHasNameCon $fHasNameName$fHasNameTyVarBndrfind$fFunctorWithIndexIntSeq$fFunctorWithIndexInt[]$fTraversableWithIndexkHashMap$fFoldableWithIndexkHashMap$fFunctorWithIndexkHashMap$fTraversableWithIndexkMap$fFoldableWithIndexkMap$fFunctorWithIndexkMap$fTraversableWithIndexIntIntMap$fFoldableWithIndexIntIntMap$fFunctorWithIndexIntIntMap$fTraversableWithIndexIntVector$fFoldableWithIndexIntVector$fFunctorWithIndexIntVector$fTraversableWithIndexIntSeq$fFoldableWithIndexIntSeq$fTraversableWithIndexInt[]$fFoldableWithIndexInt[] Data.DatagmapMDatainlinePerformIOGHC.IOunsafePerformIOFollowerOracle fromOracleAnswerMissFollowHitCacheHitMapDataBox dataBoxKey _dataBoxValFieldExceptionsteplookupondataBox sybChildren emptyHitMap insertHitMapfixEqcachereadCacheFollowerinsert2hitTest biplateData uniplateDatapartfollower$fFunctorOracle$fFunctorAnswer$fExceptionFieldException$fShowFieldExceptionGHC.ShowShowGHC.ReadReadData.Typeable.InternalTypeable<*>negate $fPlatedPat $fPlatedStmt $fPlatedType $fPlatedCon $fPlatedDec $fPlatedExp $fPlatedTree $fPlated[]<= toInteger<LeftRight fromInteger unwrapped$fWrapped[][]SetSetfromList$fWrapped[][]MapMap$fWrapped[][]IntSetIntSetData.IntSet.Base$fWrapped[][]IntMapIntMapData.IntMap.Base$fWrapped[][]HashSetHashSet$fWrapped[][]HashMapHashMap getErrorCallgetRecUpdErrorgetRecSelErrorgetRecConErrorgetPatternMatchFailgetNoMethodErrorfailedAssertion getArrowMonad$fWrapped[][]ErrorCallErrorCall#$fWrapped[][]RecUpdErrorRecUpdError#$fWrapped[][]RecSelErrorRecSelError#$fWrapped[][]RecConErrorRecConError-$fWrapped[][]PatternMatchFailPatternMatchFail'$fWrapped[][]NoMethodErrorNoMethodError+$fWrapped[][]AssertionFailedAssertionFailed$fWrapped[][]SeqSeq$fWrappedww'TracedTTracedT'$fWrappedEitherEitherCoproductCoproduct$fWrappedmm'WriterTWriterT$fWrappedmm'WriterTWriterT0$fWrapped(->)(->)StateTStateT$fWrapped(->)(->)StateTStateT0$fWrapped(->)(->)RWSTRWST$fWrapped(->)(->)RWSTRWST0$fWrappedff'ReverseReverse$fWrapped(->)(->)ReaderTReaderT$fWrappedmm'MaybeTMaybeT$fWrappedmm'ListTListT$fWrappedfgLiftLift$fWrappedmm'IdentityTIdentityT$fWrappedaa'IdentityIdentity$fWrappedmm'ErrorTErrorT$fWrapped(->)(->)ContTContT$fWrappedaa'ConstantConstant$fWrappedff'ComposeCompose$fWrappedff'BackwardsBackwards$fWrappedmnArrowMonadArrowMonad$fWrappedMaybeMaybeLastLast$fWrappedMaybeMaybeFirstFirst$fWrapped(->)(->)EndoEndo$fWrappedabConstConst$fWrapped[][]ZipListZipList#$fWrappedauWrappedArrowWrappedArrow#$fWrappedmnWrappedMonadWrappedMonad$fWrapped(->)(->)KleisliKleisli$fWrappedabProductProduct$fWrappedabSumSum$fWrappedBoolBoolAnyAny$fWrappedBoolBoolAllAllreturn>>=$fRepresentable(->)$fRepresentableIdentityfreshMap getLensFields_lensIso _lensField _lensClass _lensFlags makeIsoTo makeIsoFrom makeIsoBody makeLensBodyplainappArgsappsappsT makeIsoLensesmakeFieldLensBodymakeFieldLenses unifyTypes GHC.Exception Exception SomeException Data.Bits.|.Bits.&.bitSize undefinedGHC.WordWord8Data.ByteString.Lazy.Internal$fIsByteStringByteString$fIsByteStringByteString0realPartimagPartpolar magnitudephasepi conjugate Data.DynamicDynamicIntSettail split-0.2.1.1Data.List.Split.InternalsSplitter dropDelims onSublistoneOfwhenEltdropFinalBlank dropBlanksendkeeps Data.SequenceSeqViewLviewlViewRviewr Data.TextData.Text.Lazy.InternalData.Text.Lazy $fIsTextText $fIsTextText0 Data.TreeTree subForest Data.Typeablecastgcastvector-0.10.0.1 Data.VectorVectorlastData.Vector.GenericData.Vector.Generic.BaseData.Vector.Fusion.StreamStream GHC.GenericsGeneric tinplated maybeArg1Of$fGTraversal:.:$fGTraversalM1$fGTraversal:+:$fGTraversal:*:$fGTraversalU1$fGTraversalK1 array-0.4.0.1Data.Array.BaseIArray!//ixmapboundsamapFilePathparallel-3.2.0.3Control.Parallel.StrategiesStrategyevalTraversableEvalparTraversablerdeepseq Control.Seq seqFoldable