lens
Lenses, Folds and Traversals
http://github.com/ekmett/lens/
| Version on this page: | 4.14 | 
| LTS Haskell 24.18: | 5.3.5@rev:1 | 
| Stackage Nightly 2025-11-04: | 5.3.5@rev:1 | 
| Latest on Hackage: | 5.3.5@rev:1 | 
lens-4.14@sha256:3e28b6a161f01b027690571adf8f169c3e22ebb65fa742708c9b0d5c46977f9f,14503Module documentation for 4.14
- Control
- Control.Exception
 - Control.Lens
- Control.Lens.At
 - Control.Lens.Combinators
 - Control.Lens.Cons
 - Control.Lens.Each
 - Control.Lens.Empty
 - Control.Lens.Equality
 - Control.Lens.Extras
 - Control.Lens.Fold
 - Control.Lens.Getter
 - Control.Lens.Indexed
 - Control.Lens.Internal
- Control.Lens.Internal.Bazaar
 - Control.Lens.Internal.ByteString
 - Control.Lens.Internal.Coerce
 - Control.Lens.Internal.Context
 - Control.Lens.Internal.Deque
 - Control.Lens.Internal.Exception
 - Control.Lens.Internal.FieldTH
 - Control.Lens.Internal.Fold
 - Control.Lens.Internal.Getter
 - Control.Lens.Internal.Indexed
 - Control.Lens.Internal.Instances
 - Control.Lens.Internal.Iso
 - Control.Lens.Internal.Level
 - Control.Lens.Internal.List
 - Control.Lens.Internal.Magma
 - Control.Lens.Internal.Prism
 - Control.Lens.Internal.PrismTH
 - Control.Lens.Internal.Review
 - Control.Lens.Internal.Setter
 - Control.Lens.Internal.TH
 - Control.Lens.Internal.Zoom
 
 - Control.Lens.Iso
 - Control.Lens.Lens
 - Control.Lens.Level
 - Control.Lens.Operators
 - Control.Lens.Plated
 - Control.Lens.Prism
 - Control.Lens.Reified
 - Control.Lens.Review
 - Control.Lens.Setter
 - Control.Lens.TH
 - Control.Lens.Traversal
 - Control.Lens.Tuple
 - Control.Lens.Type
 - Control.Lens.Wrapped
 - Control.Lens.Zoom
 
 - Control.Monad
- Control.Monad.Error
 
 - Control.Parallel
- Control.Parallel.Strategies
 
 - Control.Seq
 
 - Data
- Data.Array
 - Data.Bits
 - Data.ByteString
- Data.ByteString.Lazy
 - Data.ByteString.Lens
 - Data.ByteString.Strict
 
 - Data.Complex
 - Data.Data
 - Data.Dynamic
 - Data.HashSet
 - Data.IntSet
 - Data.List
 - Data.Map
 - Data.Sequence
 - Data.Set
 - Data.Text
- Data.Text.Lazy
 - Data.Text.Lens
 - Data.Text.Strict
 
 - Data.Tree
 - Data.Typeable
 - Data.Vector
- Data.Vector.Generic
 - Data.Vector.Lens
 
 
 - GHC
- GHC.Generics
 
 - Generics
- Generics.Deriving
 
 - Language
- Language.Haskell
- Language.Haskell.TH
 
 
 - Language.Haskell
 - Numeric
 - System
- System.Exit
 - System.FilePath
 - System.IO
- System.IO.Error
 
 
 
Lens: Lenses, Folds, and Traversals
This package provides families of lenses, isomorphisms, folds, traversals, getters and setters.
If you are looking for where to get started, a crash course video on how lens was constructed and how to use the basics is available on youtube. It is best watched in high definition to see the slides, but the slides are also available if you want to use them to follow along.
The FAQ, which provides links to a large number of different resources for learning about lenses and an overview of the derivation of these types can be found on the Lens Wiki along with a brief overview and some examples.
Documentation is available through github (for HEAD) or hackage for the current and preceding releases.
Field Guide
Examples
(See wiki/Examples)
First, import Control.Lens.
ghci> import Control.Lens
Now, you can read from lenses
ghci> ("hello","world")^._2
"world"
and you can write to lenses.
ghci> set _2 42 ("hello","world")
("hello",42)
Composing lenses for reading (or writing) goes in the order an imperative programmer would expect, and just uses (.) from the Prelude.
ghci> ("hello",("world","!!!"))^._2._1
"world"
ghci> set (_2._1) 42 ("hello",("world","!!!"))
("hello",(42,"!!!"))
You can make a Getter out of a pure function with to.
ghci> "hello"^.to length
5
You can easily compose a Getter with a Lens just using (.). No explicit coercion is necessary.
ghci> ("hello",("world","!!!"))^._2._2.to length
3
As we saw above, you can write to lenses and these writes can change the type of the container. (.~) is an infix alias for set.
ghci> _1 .~ "hello" $ ((),"world")
("hello","world")
Conversely view, can be used as a prefix alias for (^.).
ghci> view _2 (10,20)
20
There are a large number of other lens variants provided by the library, in particular a Traversal generalizes traverse from Data.Traversable.
We’ll come back to those later, but continuing with just lenses:
You can let the library automatically derive lenses for fields of your data type
data Foo a = Foo { _bar :: Int, _baz :: Int, _quux :: a }
makeLenses ''Foo
This will automatically generate the following lenses:
bar, baz :: Lens' (Foo a) Int
quux :: Lens (Foo a) (Foo b) a b
A Lens takes 4 parameters because it can change the types of the whole when you change the type of the part.
Often you won’t need this flexibility, a Lens' takes 2 parameters, and can be used directly as a Lens.
You can also write to setters that target multiple parts of a structure, or their composition with other lenses or setters. The canonical example of a setter is ‘mapped’:
mapped :: Functor f => Setter (f a) (f b) a b
over is then analogous to fmap, but parameterized on the Setter.
ghci> fmap succ [1,2,3]
[2,3,4]
ghci> over mapped succ [1,2,3]
[2,3,4]
The benefit is that you can use any Lens as a Setter, and the composition of setters with other setters or lenses using (.) yields
a Setter.
ghci> over (mapped._2) succ [(1,2),(3,4)]
[(1,3),(3,5)]
(%~) is an infix alias for ‘over’, and the precedence lets you avoid swimming in parentheses:
ghci> _1.mapped._2.mapped %~ succ $ ([(42, "hello")],"world")
([(42, "ifmmp")],"world")
There are a number of combinators that resemble the +=, *=, etc. operators from C/C++ for working with the monad transformers.
There are +~, *~, etc. analogues to those combinators that work functionally, returning the modified version of the structure.
ghci> both *~ 2 $ (1,2)
(2,4)
There are combinators for manipulating the current state in a state monad as well
fresh :: MonadState Int m => m Int
fresh = id <+= 1
Anything you know how to do with a Foldable container, you can do with a Fold
ghci> :m + Data.Char Data.Text.Lens
ghci> allOf (folded.text) isLower ["hello"^.packed, "goodbye"^.packed]
True
You can also use this for generic programming. Combinators are included that are based on Neil Mitchell’s uniplate, but which
have been generalized to work on or as lenses, folds, and traversals.
ghci> :m + Data.Data.Lens
ghci> anyOf biplate (=="world") ("hello",(),[(2::Int,"world")])
True
As alluded to above, anything you know how to do with a Traversable you can do with a Traversal.
ghci> mapMOf (traverse._2) (\xs -> length xs <$ putStrLn xs) [(42,"hello"),(56,"world")]
"hello"
"world"
[(42,5),(56,5)]
Moreover, many of the lenses supplied are actually isomorphisms, that means you can use them directly as a lens or getter:
ghci> let hello = "hello"^.packed
"hello"
ghci> :t hello
hello :: Text
but you can also flip them around and use them as a lens the other way with from!
ghci> hello^.from packed.to length
5
You can automatically derive isomorphisms for your own newtypes with makePrisms. e.g.
newtype Neither a b = Neither { _nor :: Either a b } deriving (Show)
makePrisms ''Neither
will automatically derive
neither :: Iso (Neither a b) (Neither c d) (Either a b) (Either c d)
nor :: Iso (Either a b) (Either c d) (Neither a b) (Neither c d)
such that
from neither = nor
from nor = neither
neither.nor = id
nor.neither = id
There is also a fully operational, but simple game of Pong in the examples/ folder.
There are also a couple of hundred examples distributed throughout the haddock documentation.
Contact Information
Contributions and bug reports are welcome!
Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.
-Edward Kmett
Changes
4.14
- Remove 
ConsandSnocinstances forNonEmpty. 
4.13.2.1
- Fixed 
itraverse_andimapM_returning bottom 
4.13.2
- Restore default signature for 
Control.Lens.At.at - Improve operations for 
Data.Sequence.Seq - Fix 
declarePrismsbehavior on GHC 8 using GADT record syntax 
4.13.1
- Modified to enable the 
docteststo build withstack. - Removed 
.ghci. - Added 
lookupOf - Support GHC 8
 - Support 
transformers0.5 - Support 
kan-extensions5 - Support 
comonad5 - Better support for 
Closedfromprofunctors. 
4.13
- Pattern synonyms
 - Moved 
foldMapByandfoldByintoreflection2.1 - Added 
traverseByOf,sequenceByOf. - Reexported 
traverseByandsequenceByfromreflection2.1. - Modified the signatures of 
alafandaufto work with aFunctorrather than aProfunctorand rather drastically generalized them. - Removed 
Control.Lens.Internal.Getter.coercein favor of the upstreamphantomcombinator incontravariant1.3+ - Renamed 
coercedtophantasmto get it out of the way. - Added 
Wrappedinstance forDown 
4.12.3
- Move 
ReviewandAReviewtoControl.Lens.Typefixing a bug inmakePrisms - Expose 
HasTypesclass inLanguage.Haskell.TH.Lens - Make types of 
foldByOfandfoldMapByOfmore specific to hide implementation details - Add Prisms to 
Language.Haskell.THfor new constructors intemplate-haskell-2.10 - Generalize type of 
_FunDepto anIso 
4.12.2
- Incorporated a bug fix for 
foldByOfandfoldMapByOfto actually let them work on folds. - Added a 
Platedinstance forCofreeT 
4.12.1
- The 
Simpletype alias is now poly-kinded. This lets you useSimple Field1 s aand the like in constraints. - Added 
HasTypestoLanguage.Haskell.TH.Lens. - Support for 
vector-0.11.0which changesStreamtoBundle 
4.12
reflection 2support.
4.11.2
- Give 
cosmosOna more general type. 
4.11.1
- Added 
cosmos,cosmosOf,cosmosOn,cosmosOnOftoControl.Lens.Plated. - Added 
icontains,iat,iix. - Made various documentation improvements.
 - Added a 
test-templatesflag. 
4.11
- Proper 
profunctors5.1 support. This extended the superclass constraints forConjoined, so it resulted in a major version bump. 
4.10
- Added 
elemIndexOf,elemIndicesOf,findIndexOf, andfindIndicesOf. - Fixed 
Ixedinstance forTree. It no longer drops nodes prior to the traversed node. bifunctors5,profunctors5 andsemigroupoids5 support.
4.9.1
- Added 
_Wrappedsupport forNonEmpty. - Added 
_Wrappedsupport forAlt. - Fixed 
Rewrappedinstance forLast. 
4.9
filepath1.4 support- Removed 
Control.Monad.Primitive.Lensand shed theprimitivedependency. - Add missing 
_WithIndexinstances fromkeyspackage - Much more code is inferred 
Saferather thanTrustworthy. - Documented the difference between 
unsafeSingularandsingular. foldingnow produces an actualFold.- Cleaned up builds for GHC 7.10 to get rid of redundant import warnings.
 
4.8
- When built with 
profunctors4.4 on GHC 7.8+ we no longer need to useunsafeCoerceat all! This drastically reduces the level of trust involved in the way we have optimizedlens. - Added 
fusing. This optimizes longLenschains, by enfocing a form offmapfusion based on the Yoneda lemma. This is particularly effective at making faster lenses the definition is recursive or complex enough that it cannot be inlined. - Added 
confusing. This optimizes longTraversalchains. As withfusingit is best used when the definition for theTraversalchain in question is recursive or complex enough that it cannot be inlined, but the implementation is much more confusing. - Remove deprecated stuff: 
Control.Lens.Loupe,headOf,makeFieldsWith,strippingPrefix,strippingSuffix - Added 
ConsandSnocinstances forNonEmpty - Removed 
Data.List.Split.Lensmodule - Reimplemented 
bytestringtraversals to avoid internal modules - Added 
gplate, an implementation ofplatefor any type implementingGeneric - Strictness revisited
- Add 
generateLazyPatternsconfiguration flag tomakeLensesrules. - Make the default 
makeLensesbehavior to generate STRICT optics - Add strict variants of 
_1.._9named_1'.._9' 
 - Add 
 - Generalized some combinators in 
Data.Vector.Generic.Lensand addedconverted 
4.7
- Migrated 
Control.Lens.Actiontolens-action. - Added 
Data.Vector.Generic.Lens.vectorIxfunction for indexing vectors with onlyVectorconstraint. - Added 
Field1andField2instances forData.Functor.Product.Product. - Removed the “typeclass synonym” 
Gettable. - Added new flag to 
makeLenses,generateUpdateableOptics, which allows the generation of onlyGetters andFolds. This feature is intended to be used when the constructors are hidden behind validating, “smart” constructors. - Fixed Template Haskell name generation when using GHC 7.10
 - Fixed Template Haskell generation of classes methods where field types used existential quantification
 
4.6.0.1 [maintenance release]
- Compatibility with 
base4.8 [Edit: this turned out to not work for the final release of GHC 7.10] 
4.6
- Reduced 
Reviewto two arguments, likeGetter. - Added 
abbreviatedFieldsto permitmakeFieldsWithto be invoked with an argument that lets it act like it did pre-4.5 and accept arbitrary common prefixes. 
4.5
- Provide access to the typename in 
lensRulesnaming function. makeFieldscamelcasing rules now properly support types with camelcasing.MyTypewith fieldmyTypeFieldAgeneratesfieldAnow. Previously the prefix ignore capitalization and the field would need to be namedmytypeFieldA.makeClassyworks on types even when none of the fields would generate optics.- Added 
Monad,MonadReader,MonadPlusandBindinstances forReifiedMonadicFold - Added missing fixity declarations on many operators.
 - Migrated 
Codec.Compression.Zlib.Lenstozlib-lenspackage. 
4.4.0.2
text1.2.0.0 support- Remove the use of the TemplateHaskell extension from the library to enable lens to be used on stage1 cross-compilers
 
4.4.0.1
- Restore previous default of 
makeFieldsusing the camel case field namer. 
4.4
- Internals of Template Haskell code generation rewritten. makeLenses, makeClassy, and makeFields have been unified into the same generator.
 - TH generated single constructor Lens use irrefutable pattern matching to enable construction starting with undefined.
 - TH generated traverals unify their field arguments (type synonyms not currently expanded) enabling exotic traversals to be generated.
 - Added instances for 
TexttoData.Aeson.Lens - Reimplemented 
makePrisms, adding support formakeClassyPrisms, infix constructrs generate periods (.) prefixed prisms. - Added 
ChoicetoReviewso thatPrismis a proper subtype ofReview - Migrated 
Data.Aeson.Lenstolens-aesonpackage. - Fixed 
GHC.Generics.Lens.tinplatebehavior on single-field data types and empty data types. 
4.3.3
semigroupoids4.2 support
4.3.2
contravariant1.0 support
4.3.1
- Added 
bytewisetoData.Bits 
4.3
- Switched the “direction” of the 
Isoargument toauto match the order generated bymakePrismsandmakeLenses. - Removed 
makeIsosin favor ofmakePrismsandmakeLenses. Each of these functions will constructIsos when appropriate. - Removed 
declareIsosin favor ofdeclarePrismsanddeclareLenses. Each of these functions will constructIsos when appropriate. - Added 
matchingfor type-changing matches withPrisms. - Added 
withPrismfor recovering the functions passed toprism. - Added 
negated, the isomorphism for thenegatefunction. 
4.2
- Added 
_Textisomorphisms to make the proper use with(#)more obvious and fit newer convention. - Added 
Wrappedinstances forVectortypes - Resolved issue #439.  The various 
Prisms for string-like types inData.Aeson.Lensare now law-abidingPrisms “up to quotient.” - Added 
selfIndex. - Support 
attoparsec0.12. 
4.1.2
- When used with 
exceptions0.4,throwingMwill permit use with a mereMonadThrow. 
4.1.1
- Generalized the types of 
mapping,bimapping,contramapping,dimapping,lmapping,rmappingto support changing theFunctor,Bifunctor,Contravariant, andProfunctorrespectively. - Compatibility with 
free4.6 
4.1
- Added 
Platedinstances for various free monad variants. - Compatibility with GHC HEAD (7.9+)
 
4.0.7
- Removed dependency on 
constraints. It was used in a pre-release version of 4.0 but never made it into 4.0, but the dependency had remained around complicating builds for GHC 7.4. 
4.0.6
makeLensesattempt to make the accessors it can under existential quantification.- Added 
(&~). - Experimental support for parallel builds on GHC 7.8 with 
cabal install lens -fj. Due to at last one known issue with GHC, it isn’t recommended to use this option when rebuilding lens, as a race condition on at least one platform has been seen in the wild. - Added 
RoleAnnotationsfor GHC 7.8.1. These rule out a few user-accessible bottoms that could be caused by creative abuse of the newCoerciblemachinery. However, there was nounsafeCoerceexposed. - Removed some impossible cases that required unwritable instances from the example doctypes.
 
4.0.5
- Added 
bimappingtoControl.Lens.Iso - Restored correct behavior of 
makePrismon types with a single constructor. makeLensesnow generatesGetters andFolds on universally quantified fields.
4.0.4
- Made 
declareFieldswork again. 
4.0.3
- Fixed random segfaulting when using 
foldMapBy. 
4.0.2
- Properly bundled the modules needed for the properties test suite into the tarball for hackage.
 
4.0.1
- Typo fixes
 - Exporting 
RewrappingfromControl.Lens.Wrapped. - Removed the dependency on 
cpphs. 
4.0
- Added 
nearlytoControl.Lens.Prism. - Added 
Control.Lens.Empty, exporting_Empty. - We now require 
DefaultSignatures. - Added 
failingandifailingtoControl.Lens.Traversal. - Changed the signature of 
Data.List.Split.Lens.condensingdue to the addition ofDropBlankFieldstoData.List.Split.CondensePolicyinsplit. - Simplified 
Each,Ixed, andContains. They are no longer indexed. The previous design was actively getting in the way of user-defined instances. - Replaced more of our home-grown types with standard ones. They had previously been defined to help make more intelligible error messages, but when we switched to using 
(Contravariant f, Functor f)instead of(Gettable f), these ceased to really help. Now you can define even morelens-compatible types (e.g.GetterandFold) without depending onlens.- Replaced the use of 
AccessorwithConst. - Replaced the use of 
MutatorwithIdentity. - Replaced the use of 
ReviewedwithTagged. 
 - Replaced the use of 
 - Removed the deprecated 
Control.Lens.Simplemodule. - Repurposed 
Control.Lens.Combinatorsto re-exportControl.Lenssans any operators; previous residents rehomed toControl.Lens.Lens. - Added 
Control.Lens.Operatorsto export just the operators. Varying your import styles between these supports many qualified usage scenarios. - Simplified 
ConsandSnoc. Now they must be aPrism. - Simplified 
Contains. This necessitated losing many instancs ofContains, but makes it much easier and more consistent to use and instantiate. - Simplified the various 
AsFootypes inControl.Exception.Lens - Simplified the types in 
System.IO.Error.Lens. - Merged 
lens-aesonintolens. - We’re exiling 
Control.Lens.Zipperto a separate package. This will let the design for it iterate faster and let us explore the trade-offs between the 3.8 style and the 3.9 style of zippers. - Generalized 
alongside,inside,both. - Switched to a new 
Typeableversion ofreflectionfor the harder combinators inControl.Exception.Lens. This enables us to comply with GHC 7.7’s ban on hand-writtenTypeableinstances. - Added a 
_ShowPrism. - Added 
Control.Lens.Extrasfor the combinator names we don’t have the gall to claim outright, but which are consistent with the rest. - Renamed the constructors for 
ReifiedLens, etc. to just be the name of their base type. - Added many many missing instances for 
ReifiedFoldandReifiedGetter. This permits things likerunFold ((,) <$> Fold (traverse._1) <*> Fold (traverse._2))to be aFoldandReifiedFoldcan be used as aMonad,Profunctor, etc. - Many performance optimizations.
 - Switched to 
exceptionsfromMonadCatchIO-transformers - Added types for working with 
RelevantFoldandRelevantTraversal. These are aFoldorTraversalthat always has at least one target. SinceApplyisn’t a superclass ofApplicative, you occasionally need to convert between them, but it lets you more readily work with less unsafety. - Changed 
unwrappingandwrappingto have the same constructor-oriented order as aPrismand renamed them t_Wrappingand_Unwrappingrespectively. - Drastically changed the way 
_Wrappingand_Unwrappingare built to get much better inference. - There are about 15,000 lines of patches over the last year, so I’m sure we missed a few big changes.
 
3.10.1 [maintenance release]
- Compatibility with 
base4.7 
3.10.0.1 [maintenance release]
- Compatibility with 
text1.0 
3.10
- Switched to 
bifunctors,comonad,profunctors, andsemigroupoids4.0. 
3.9.2
- Generalized signatures for 
throwingandthrowingM. 
3.9.1
- ‘condensingPolicy’ was updated to work with ‘split’ 0.2.2
 
3.9.0.3
- Bumped dependency on 
generic-derivingagain. 
3.9.0.2
- Bumped dependency on 
generic-derivingto enable building on GHC HEAD. 
3.9.0.1
- Updated the field guide image to link to imgur. Sadly the overview haddock and the haddocks are not generated in the same directory, so the haddock hook for copying the image only works locally.
 
3.9
- Changed 
Gettingto take 3 arguments instead of 5. If you need the old behavior for portability you can useOverloaded (Accessor r) s t a binstead ofGetting r s t a band it’ll work consistently back through the last few releases. - Added 
involutedtoControl.Lens.Iso. - Factored out a common 
reverseddefinition from all the various forms of it around the library and placed it inControl.Lens.Iso. - Added 
binary,octal,decimalandhextoNumeric.Lens. - Added 
sanstoControl.Lens.At. - Improved interoperability:
- Reimplemented 
Gettableas an alias forContravariantandFunctortogether to deriveGetterandFold. This means you can now implement aGetterorFoldwith only a Haskell 98 dependency (contravariant). - Removed 
Reviewable. We now useBifunctorandProfunctortogether to deriveReview. This means you can now implement aReviewwith Haskell 98 dependencies (profunctorsandbifunctors). - These changes enables more types to be defined without incurring a dependency on the 
lenspackage. 
 - Reimplemented 
 
3.8.7.0-3.8.7.3 [maintenance releases]
- Fixes to dependencies and pragmas.
 
3.8.6 [maintenance release]
- Fixed an issue with 
DefaultSignaturesbeing used outside of the appropriate#ifdefthat caused compilation issues on GHC 7.0.2. - Generalized the signature of 
prism' - Added 
\_VoidandonlytoControl.Lens.PrismanddevoidtoControl.Lens.Lens. - Added 
\_NothingtoControl.Lens.Prism. - Added 
devoidandunitedtoControl.Lens.Lens. 
3.8.5
- Fixed more sporadic issues in doctests, caused by carrying flags from 
$setupbetween modules. 
3.8.4
- Renamed 
strippingPrefixtoprefixed,strippingSuffixtosuffixed. Left the old names as deprecated aliases. - Fixed issues with the test suite caused by 
doctestscarrying flags from the$setupblock between modules. - Benchmarks now use 
generic-derivingrather thanghc-primdirectly, like the rest of the package. - Added 
Generics.Deriving.Lens, which is now simply re-exported fromGHC.Generics.Lens. 
3.8.3
- Added 
strippingSuffixandstripSuffixtoData.Data.Lens - Added 
unpackedBytesandunpackedCharstoData.ByteString.*.Lens - Added 
unpackedtoData.Text.*.Lens - Added 
(#)as an infix form ofreviewto ease using aPrismlike a smart constructor inControl.Lens.Review. 
3.8.2
- Added a notion of 
Handleable(handler, handler_)toControl.Exception.Lensto facilitate constructing aHandlerfrom an arbitraryFoldorPrism. - Added a notion of 
Handlerandcatchesto andControl.Monad.Error.Lensto mirror theControl.ExceptionandControl.Monad.CatchIOconstructions. - Added additional doctests and documentation.
 - Improved error messages and support for types with arguments in 
makeFields. 
3.8.1
- Fixed a bug in 
makeFieldsin hierarchical modules. 
3.8.0.2
- Fixed an issue with running the 
docteststest suite when an older version ofsemigroupsis installed. 
3.8
- Overall:
- Replaced each of the different 
SimpleFootype aliases withFoo'throughout. The variousSimplealiases can still be found inControl.Lens.Simplebut are now deprecated. - Made sweeping changes to 
IsoandPrismandIndexedlenses internally. They are now based onprofunctors. This affects how you useindexedin the resulting code and dramatically changed the meaning ofOverloaded. - Generalized combinators to pass through indices unmodified wherever possible and added indexed variants to existing combinators. There are hundreds of these changes and they would swamp this list.
 
 - Replaced each of the different 
 Control.Exception.Lens- This module was created to add combinators and prisms that make it possible to work with GHC’s extensible exceptions and monad transformer stacks more easily. There are knock-on changes in 
Data.Dynamic.Lens,System.Exit.Lens, andSystem.IO.Error.Lens. 
- This module was created to add combinators and prisms that make it possible to work with GHC’s extensible exceptions and monad transformer stacks more easily. There are knock-on changes in 
 Control.Lens.At- Moved 
At(at)andContains(contains)and factored outIxed(ix). - Deprecated 
_atandresultAt. - Removed various 
ordinalandixcombinators, which are subsumed byIxed(ix). 
- Moved 
 Control.Lens.Cons- Consoldiated the various 
_head,_tail,_initand_lasttraversals that were scattered around the place into a pair ofConsandSnocclasses that provide_Consand_Snocprisms respectively, and combinators that build on top. 
- Consoldiated the various 
 Control.Lens.Each- Generalized the signature of 
Eachto permit it to provide anIndexedSetterfor((->) e). Eachnow uses anIndextype family that is shared withAt,IxedandContainsto indicate these operations are related.
- Generalized the signature of 
 Control.Lens.Equality- Added as a stronger form of 
Isothat can be used to safely cast. - Added the adverb 
simply, which can be used to simplify the types of most combinators in the library so they only take a simple lens, simple traversal, etc as their first argument instead. e.g.simply viewforcesa ~ b,s ~ tin the argument toview. 
- Added as a stronger form of 
 Control.Lens.Fold- Added 
foldr1Of'andfoldl1Of'. - Added 
hasandhasn't. 
- Added 
 Control.Lens.Indexed- The various indexed combinators for each type were distributed to their respective modules. This module grew to encompass the remaining index-specifics.
 - Added 
indexandindices, and removediwhereandiwhereOf. Useitraversed.indices evenandbar.indices (>3)instead. 
Control.Lens.Internal- This module was exploded into more manageable component modules.
 
Control.Lens.IsoStrict(strict)is now aSimple Iso.- Added 
magmaandimagmawhich can be used to provide a ‘debugging view’ of aTraversal. 
Control.Lens.Lens- Restructuring split this module out from 
Control.Lens.Typeand merged the contentsControl.Lens.IndexedLens. 
- Restructuring split this module out from 
 Control.Lens.Level- This module was created to provide the breadth-first-search Traversals 
levelsandilevelswhich can be used to do (optionally depth-limited) breadth-first searches through arbitrary traversals reaching all leaves at finite depth in finite time. To use these in full accordance with the laws you should restrict yourself to commutative operations and finite containers, but they are useful even in the absence of these properties. 
- This module was created to provide the breadth-first-search Traversals 
 Control.Lens.Loupe- In the interest of consistency, the 
Loupealias has been deprecated in favor ofALens. Loupe(andALens) are now defined in terms ofPretextrather thanContext. This permits them to be cloned at a reduced cost reducing the call forReifiedLens.
- In the interest of consistency, the 
 Control.Lens.Operators- Added this module for users who insist on qualified use, but want access to the operators. They can 
import qualified Control.Lens as Lensandimport Control.Lens.Operatorsunqualified. 
- Added this module for users who insist on qualified use, but want access to the operators. They can 
 Control.Lens.Prism- Added 
prism'to constructSimplePrisms. 
- Added 
 Control.Lens.Reified- Consolidated the various 
ReifiedFoodefinitions into one module. 
- Consolidated the various 
 Control.Lens.Representable- This module was removed. Its functionality may be split out into a separate package, but currently the 
linearpackage exports is ownLinear.Coremodule to provide this functionality. It was taking lots of useful names for little functionality and didn’t feel like the rest of the API. 
- This module was removed. Its functionality may be split out into a separate package, but currently the 
 Control.Lens.Review- This module now factors the 
reviewfunctionality out ofPrismand exposesunto, which is toreviewwhattois toview. 
- This module now factors the 
 Control.Lens.Setter- Added 
contramappedandargumentfor mapping over inputs. 
- Added 
 Control.Lens.Simple- Removed the infix lens aliases and repurposed the module to house the now deprecated 
SimpleFootype aliases, which were replaced universally withFoo'. 
- Removed the infix lens aliases and repurposed the module to house the now deprecated 
 Control.Lens.THmakeLensesnow generatesLens'andTraversal'where appropriate- Added 
makePrismsas a generalizedmakeIsothat automatically generates aPrismfor each constructor.makePrismsgenerates names with an_Fooconvention. This was consolidated upon throughout the library to reduce namespace conflicts between prisms and lenses. - Added 
makeFields, which generates classes for each individual field in a data type. - Added 
makeWrapped, which automatically generates aWrappedinstance for a newtype. 
Control.Lens.Type- This module was repurposed to provide a single home for all the standard lens-like type aliases used when producing lenses. You still need to go to their respective modules to find the types for consuming lens-likes if you want to generate your own lens combinators
 
Control.Lens.Wrapped- Added 
wrapped'andunwrapped'for scenarios where you need the help with type inference. 
- Added 
 Control.Lens.Zipper- Converted 
Zipperto walk a magma based on the original structure and to use indices from indexed traversals when restoring from tape. This also means that when zipping around within a balanced structure with ascending keysmoveTocan operate in logarithmic time, but required changing theZippertype to add the index type. 
- Converted 
 Data.Bits.Lens- Added 
byteAt. 
- Added 
 Data.ByteString.LensData.ByteString.Lazy.Lensnow usesInt64-based indexing.- The 
Traversalfor strictByteStringsnow construct a balanced tree up to a given grain size. This permits zipper based seeking to operate in logarithmic time and speeds up many traversals. 
Numeric.Lens- Created. 
baseshows and reads integers at base-2 through base-36.integralcan be used as a safefromInteger/toInteger. 
- Created. 
 
3.7.6 [maintenance release]
- Fixed an issue with the 
ComplexEachinstance. 
3.7.5 [maintenance release]
- Fixed an errant 
LANGUAGEpragma 
3.7.4 [maintenance release]
- Backported the API for 
ALensandALens'to supportsnapbuilds on old platforms. 
3.7.3 [maintenance release]
- Removed my intra-package dependency upper bounds for my own packages. In particular this enables us to work with 
semigroups0.9. - Switched to 
transformers-compatto avoid having unbuilding modules at the top of the documentation, and to ease 3rd party compatibility. - Updated 
Setup.lhsto be compatible with Cabal 1.17 
3.7.2 [maintenance release]
- Bug fix for 
Magnify. It was missing functional dependencies to determine itskparameter frommorn. 
3.7.1.2 [maintenance release]
- Made the doctest test suite hide all but the exact versions of packages used to build this package to avoid problems with complicated user environments.
 - Removed doctests based on 
:tas they are fragile and break across GHC versions. - Fixed GHC 7.0.4 compatibility by guarding 
DefaultSignaturesinControl.Lens.Each. 
3.7.1.1 [maintenance release]
- Removed tests that will (likely) fail in the presence of 
hashable1.2 
3.7.1
- Added 
preuse,preusestoControl.Lens.Fold - Added 
Each(each)toControl.Lens.Eachfor indexed traversal of potentially monomorphic containers. - Added 
indexing64andtraversed64for help with large containers. - Generalized the type signature of 
choosing. - Exported 
unwrappedfromControl.Lens.Wrapped. - Support for 
hashable1.2 - Added 
(??)toControl.Lens.Combinators. 
3.7.0.2
- Fixed flagging for Safe Haskell.
 - Fixed examples.
 - Cleaned up the statement of the Prism laws.
 
3.7.0.1
- Corrected bounds for hashable.
 - Fixed compatibility with Haskell Platform 2011.4.0.0 – you may have to install with –constraint=“transformers = 0.2.2.0” to avoid getting new mtl and transformer versions installed.
 
3.7
- Renamed 
ProjectiontoPrism. - Implemented a complete redesign of the way 
IsoandPrismare handled internally. AnyIsocan now be used as aPrism. - The 
isoscombinator is no longer required.isocan now be used to construct anIso. - Changes to the signature of 
fromandunderwere necessitated by the new design. - Added 
Control.Lens.Wrappedproviding a canonical isomorphism for newtypes. - Repurposed 
alato be closer to the original design innewtype, but addedauandalaf. - Added 
_magnitude,_phaseand_conjugatetoData.Complex.Lens. Renamed other lenses for consistency:_realPart,_imagPart,_polar. - Promoted 
_leftand_rightto prisms and moved them toControl.Lens.Prism. - Generalized 
viewandviewsto subsume the old functionality ofperuseandperuses. - Generalized 
reviewandreviewsto both return aMonadReaderand to work on aProjection. - Added 
view'/views'anduse'/uses'forSimpleaccess to the environment/state. - Added 
set', aSimpleversion ofset. - Added 
reuse:use::review:viewandreuses:uses::reviews:viewsfor working aProjectionfrom the currentMonadState. - Removed many isomorphisms for various newtypes. 
_const,identity,_sum, etc. Usewrapping Const,wrapping Identity, etc. - Removed 
Data.Monoid.Lensnow that its newtypes are instances ofWrapped, exporting the (<>=)-variants fromControl.Lens.*. - Renamed 
viatocloneIsofor consistency. - Moved 
Indexed(..)toControl.Lens.Classes. - Renamed 
indextoindexedto reduce conflicts with third-party libraries. - Added 
curriedanduncurriedtoControl.Lens.Iso. - Added 
Strict(strict)for ad hoc overloading of conversions between strict and lazy variants ofByteStringandText. - Bug fixes for 
tugToandjerkTo. - These no longer traverse in the wrong direction: 
scanl1Of,scanr1Of,mapAccumLOf, andmapAccumROf. - Added 
anontoControl.Lens.Iso. - Generalized the types of the 
Control.Lens.Zippercombinators to work with other MonadPlus instances. - Added 
withinstoControl.Lens.Zippernow that they can work better with []. - Added 
singularandunsafeSingulartoControl.Lens.Traversalto assert aTraversalis aLens, aFoldis aGetteror aMonadicFoldis anAction. - Generalized 
sequenceAOf_’s type to matchsequenceA_. - Renamed 
up/down/left/righttoupward/downward/leftward/rightwardto reduce conflicts – in particular withControl.Arrow. - Readded 
leftmostandrightmostdue to the verbosity offarthest leftward/farthest rightward. - Added 
preview/previews/firstOfand deprecatedheadOf. - Added 
iview/iviews/iuse/iusestoControl.Lens.IndexedGetter. - We’ve generalized the type of Bazaar and provided generalized variants of 
partsOf, etc. that used it. 
3.6.0.4 [maintenance release]
- Added support for 
test-framework0.8 
3.6.0.3 [maintenance release]
- Added support for 
test-framework0.7 
3.6.0.2 [maintenance release]
- Added more explicit dependencies to the doctest suite.
 - Disabled the ‘expected failure’ quickcheck tests that occasionally would fail with internal QuickCheck errors.
 
3.6.0.1 [maintenance release]
- Added explicit dependency on containers and unordered-containers to the doctest suite
 
3.6
- Added 
upon(along with variants of it) toData.Data.Lens, which can be used to generate aTraversalfrom a field accessor or any function that returns, unmodified, a single field that would be visited bytemplate. - Added some missing 
examples/files to the distribution. - Renamed 
Data.Bits.Lens.traverseBitstobits. - Removed 
(^!?), which was an alias for(^?!). - Removed the need for 
Trustworthyby changing the implementation ofcoerceforBazaarT. - Moved BazaarT to 
Control.Lens.Internal. - Added 
(<&>)toControl.Lens.Combinators. elementandelementOfare now indexed traversals rather than lenses and have moved toControl.Lens.IndexedTraversal. This both fixes their former partiality and lets you use chain indexed combinators with them.- Added 
elementsandelementsOfas indexed traversals for ordinal indexing into regular traversals that generalizeelementandelementOf. - Renamed 
Data.Complex.Lens.traverseComplextocomplex. - Changed 
Data.Complex.Lens.polarizeto aSimple Iso, due to theRealFloatconstraint causing inference problems. - Renamed 
traverseLeftandtraverseRightto_leftand_rightrespectively. - Renamed 
traverseSlice,traverseFrom, andtraverseToinData.Sequence.Lenstosliced,slicedFrom, andslicedTorespectively. - Renamed 
traverseAtto_atinControl.Lens.IndexedTraversal. - Renamed 
traverseArrayto_arrayinData.Array.Lens. - Renamed and made the combinators in 
Control.Lens.Zippermore compositional to reduce third-party naming conflicts down to justleftandright. - Renamed 
&=and|=to.&.=and.|.=for consistency, mutatis mutandis their related operations. - Added a 
Platedinstances forLanguage.Haskell.THtypes. - Renamed 
atIndexandatIndicesinData.Vector.LensandData.Vector.Generic.Lenstoordinalandordinalsto matchData.Sequence.Lens 
3.5.1
- Improved SafeHaskell inference.
 
3.5
- Fixed a potential SafeHaskell issue where a user could use 
undefinedto deriveunsafeCoerce. You now have to import an explicitly Unsafe module and create an instance ofTrustworthyfor your type to cause this behavior, so if you do, it’s on your head, not mine. :) - Renamed 
EvilBazaartoBazaarT. - Moved a lot of internals around. Most notably, 
Gettable,SettableandEffectivehave moved toControl.Lens.Classes. - Exposed 
partsOf'andunsafePartsOf'inControl.Lens.Traversalto reduce reliance onBazaarTinControl.Lens.Zipper 
3.4
- Renamed 
(%)to(&)and(^%)to(^&). This avoids the conflict withData.Ratio, which was our highest priority conflict with a third party library. - Switched to a more liberal type for 
ignored - Removed some “
isplitting” bad combinators fromControl.Lens.IndexedFold. - Made 
indexed,taking, anddroppingandelementOflazier and capable of dealing with infinite traversals and infinite folds. - Improved 
Indexingto support infinite traversals and folds. - Removed some of the more redundant combinators from 
Control.Lens.Plated, which already had existing aliases in the rest of the traversal API. - Moved 
partsOf,holesOf, andelementOfintoControl.Lens.Traversal. - Renamed 
querytoperuseandqueriestoperuses. These are much less contentious names, both containusein their name for analogy touseandusesand the word is about reading. - Simpler 
simple. - Added 
enumandnontoControl.Lens.Iso. - Added 
(^?!)toControl.Lens.Foldfor unsafe access to the head of aFold. - Changed 
_head,_tail,_initand_lastto traversals inData.List.LensandData.Sequence.Lens. - Eliminated 
traverseHead,traverseTail,traverseInitandtraverseLast. partsOfandunsafePartsOfcan now also be applied to aFoldyielding aGetteror to aMonadicFoldyielding anAction.
3.3
- Redefined 
simpleand moved it toControl.Lens.Iso. Instead of usingsimple lyou can now composel.simpleorsimple.lproviding more nuanced control and a more compositional API. - Moved the various 
foo#combinators used to emit cleaner core into an unexported module,Control.Lens.Unsafe. This removesMagicHashfrom the public API. - Removed the 
bazaar#andrunBazaar#coercions that caused issues on GHC HEAD. - Changed the default definition of 
platetouniplatefromignored. - Added 
Data.Vector.Lensand instances forData.Vector. - Added support for the 
splitpackage, which is now part of the Haskell platform. - Removed redundant 
Data.List.traverseList. Useitraversedortraverseinstead. - Moved 
(:<->)toControl.Lens.Simple. - Fixed a bug in 
Control.Lens.THthat was causingmakeIsonot to work. - Added 
liftedtoControl.Lens.Setterfor mapping over monads. - Added 
besidetoControl.Lens.Traversal. - Removed the operators from 
Data.List.Lens, they broke the overall pattern of the rest of the API, and were terrible clutter. - Fixed a bug that caused 
resultAtto give wrong answers most of the time. - Changed 
resultAtto anIndexedLensand moved it toControl.Lens.IndexedLens - Changed 
ignoredto anIndexedTraversaland moved it toControl.Lens.IndexedTraversal - We’ve relinquished the name 
value. 
3.2
- Made 
elementOflazier and moved it fromControl.Lens.TraversaltoControl.Lens.Plated. - Made 
holesOfandpartsOflazier to deal with infinite structures. - Resolved issue #75. We now generate nicer core for most 
SetterandFoldoperations, and some others. - Made lenses for field access like 
_1,_2, etc. lazier. - Added 
Control.Lens.Loupe, which provides a limited form ofLensthat can be read from and written to and which can compose with other lenses, but can also be returned in a list or as a monadic result, but cannot be used directly for most combinators without cloning it first. It is easier to compose than aReifiedLens, but slightly slower. - Moved (
:=>) and (:->) intoControl.Lens.Simple, which is not exported byControl.Lensby default to reduce name conflicts with third party libraries. 
3.1
- Simplified the type of 
filtered, so that it can be composed with other folds rather than be parameterized on one. Included the caveat that the newfilteredis still not a legalTraversal, despite seeming to compose like one. - Renamed 
ifilteredtoifiltering, and while it still must take an indexed lens-like as an argument, I included a similar caveat about the result not being a legalIndexedLenswhen given anIndexedLens. The function was renamed because its signature no longer lined up with the newfilteredand the gerundive ‘-ing’ suffix has come to indicate an operator that transformers another lens/traversal/etc. into a new one. - Added 
takinganddroppingtoControl.Lens.Traversal. 
3.0.6
- Alpha-renamed all combinators to a new scheme. Instead of 
Foo a b c d, they now followFoo s t a b. This means that you don’t need to alpha rename everything in your head to work through the examples, simplifies exposition, and uses s and t for common state monad parameters. Thanks go to Shachaf Ben-Kiki for the grunt work of slogging through hundreds of definitions by hand and with regular expressions! - Restored lenses to 
Trustworthystatus so they can be used with Safe Haskell once more. 
3.0.5
- Fixed a bug in 
rights1andlefts1inControl.Lens.Zipperwhich would cause them to loop forever when given a 0 offset. 
3.0.4
- Added 
?~,<?~,?=and<?=toControl.Lens.Setterfor setting the target(s) of a Lens toJusta value. They are particularly useful when combined withat. 
3.0.3
- Refined the behavior of 
substTypeinControl.Lens.THto match the behavior oftypeVarsExwhen moving under binders. 
3.0.2
- Added 
generateSignaturesoption toControl.Lens.THto allow the end user to disable the generation of type signatures for the template-haskell generated lenses. This lets the user supply hand-written haddocks and more restricted signatures. 
3.0.1
- Added 
Control.Lens.Type.simple. 
3.0
- Added 
Control.Lens.Zipper. - Added 
<<~, a version of<~that supports chaining assignment. - Added 
:->,:=>, and:<->as type operator aliases forSimple Lens,Simple Traversal, andSimple Isorespectively. 
2.9
- Added 
<<%~,<<.~,<<%=and<<.=for accessing the old values targeted by aLens(or a summary of those targeted by aTraversal) - Renamed 
|>to%, as%~is the lensed version of%, and moved it toControl.Lens.Getteralong with a version^%with tighter precedence that can be interleaved with^. - Upgraded to 
doctest0.9, which lets us factor out common$setupfor our doctests - Renamed 
mergedtochoosing. Added a simplerchosenoperation to mirrorboth. - Added 
Control.Lens.Projection - Renamed 
traverseExceptiontoexceptionandtraverseDynamictodynamic, upgrading them to useProjection. makeClassynow places each generatedLensorTraversalinside the class it constructs when possible. This makes it possible for users to just exportHasFoo(..), rather than have to enumerate each lens in the export list. It can only do that if it creates the class. If thecreateClassflag is disabled, then it will default to the old behavior.- Added 
performstoControl.Lens.Actionto mirrorviewsinControl.Lens.Getter. 
2.8
- Restored compatibility with GHC 7.2. This required a major version bump due to making some MPTC-based default signatures conditional.
 
2.7.0.1
- Added the missing 
Control.Lens.Combinatorsto exported-modules! Its absence was causing it not to be included on hackage. 
2.7
- Generalized the signature of 
Getting,ActingandIndexedGettingto help out with the common user code scenario of needing to read and then write to change types. - Documentation cleanup and additional examples.
 - Renamed 
autoala, introducing further incompatibility with thenewtypepackage, but reducing confusion. - Removed need for 
Data.Map.LensandData.IntMap.Lensby addingTraverseMinandTraverseMaxtoControl.Lens.IndexedTraversal. - Flipped fixity of 
~:and<~: - Added 
++~,++=,<++~and<++=to Data.List.Lens in response to popular demand. - Added 
|>,<$!>and<$!toControl.Lens.Combinators, which exports combinators that are often useful in lens-based code, but that don’t strictly involve lenses. - Added an HUnit-based test suite by @orenbenkiki
 
2.6.1
- Fixed bugs in 
Traversalcode-generation. 
2.6
- Added build option 
-f-inliningto facilitate building with the various TH 2.8 versions used by GHC 7.6 and HEAD. - Added build option 
-f-template-haskellfor testing without template haskell. (Users should be able to assume TH is enabled; use this only for testing!) - Added support for generating a 
Traversalrather than aLenswhen multiple fields map to the same name or some constructors are missing a field. - Removed 
_from the lens names inSystem.FilePath.Lens. - Added 
iwhere,withIndices,withIndicesOf,indicesandindicesOfto ease work with indexed traversals - Added 
assignas an alias for(.=)inControl.Lens.Setter. - Added 
~:,=:,<~:and<=:toData.List.Lens 
2.5
- Added 
Control.Lens.Plated, a port of Neil Mitchell’suniplatethat can be used on anyTraversal. - Added 
Data.Data.Lenswith smart traversals that know how to avoid traversing parts of a structure that can’t contain a given type. - Added 
Data.Typeable.Lenswith_castand_gcastliketraverseData - Renamed 
IndexedStoretoContextnow that it is used in user-visible locations, and since I also use it asuniplate’s notion of a context. - Renamed 
KleenetoBazaar– “a bazaar contains a bunch of stores.” - Added 
Comonadinstances forContextandBazaar, so we can use stores directly as the notion of an editable context in uniplate - Compatibility with both sets of template haskell quirks for GHC 7.6.1-rc1 and the GHC 7.6.1 development head.
 - Renamed 
childrentobranchesinData.Tree.Lens. - Added 
AtandContainstoControl.Lens.IndexedLens. - Added 
FunctorWithIndex,FoldableWithIndex, andTraversableWithIndexunderControl.Lens.WithIndex - Added support for 
unordered-containers. 
2.4.0.2
- GHC 7.6.1 development HEAD compatibility (but broke 7.6.1-rc1)
 
2.4.0.1
- Haddock cleanup
 
2.4
- Added the indexed 
Kleenestore toControl.Lens.Internal - Moved 
Gettable,Accessor,SettableandMutatortoControl.Lens.Internal - Added 
cloneTraversaltoControl.Lens.Traversal - Renamed 
clonetocloneLensinControl.Lens.Type - Generalized the type of 
zoomto subsumefocus. - Removed 
Focus(..)fromControl.Lens.Type. - Factored out 
Control.Lens.Isomorphic. - Moved many private types to 
Control.Lens.Internal - Added 
conFieldstoLanguage.Haskell.TH.Lens. - Added 
System.FilePath.Lens. 
2.3
- Added missing 
{-# INLINE #-}pragmas - Renamed 
meanwhiletothroughoutinControl.Parallel.Strategies.Lens - Added 
MagnifytoControl.Lens.Getter. - Added 
ZoomtoControl.Lens.Type. 
2.2
- Added 
<&=,<&~,<|=, and<|~ - Moved 
<>~,<<>~,<>=, and<<>=toData.Monoid.Lens - Template Haskell now uses eager binding to avoid adding dependencies.
 
2.1
- Renamed 
adjusttoover - Added 
au,aufandunder - Added 
Data.Monoid.Lens - Increased lower dependency bound on 
mtlfor cleaner installation. 
