microlens
A tiny lens library with no dependencies
http://github.com/monadfix/microlens
| Version on this page: | 0.4.13.1 |
| LTS Haskell 24.45: | 0.4.14.0 |
| Stackage Nightly 2026-06-12: | 0.4.14.0 |
| Latest on Hackage: | 0.5.0.0 |
microlens-0.4.13.1@sha256:0cd8a0da5fe1b5a5c327bb5296d30940dc9f92c169372939bfcecd3faee953d7,4642Module documentation for 0.4.13.1
NOTE: If you're writing an app, you probably want microlens-platform – it has the most features. microlens is intended more for library writers who want a tiny lens library (after all, lenses are pretty useful for everything, not just for updating records!).
This library is an extract from lens (with no dependencies). It's not a toy lenses library, unsuitable for “real world”, but merely a small one. It is compatible with lens, and should have same performance. It also has better documentation.
There's a longer readme on Github. It has a migration guide for lens users, a description of other packages in the family, a discussion of other lens libraries you could use instead, and so on.
Here are some usecases for this library:
You want to define lenses or traversals in your own library, but don't want to depend on lens. Having lenses available often make working with a library more pleasant.
You just want to be able to use lenses to transform data (or even just use
over _1to change the first element of a tuple).You are new to lenses and want a small library to play with.
However, don't use this library if:
You need
Isos,Prisms, indexed traversals, or actually anything else which isn't defined here (though some indexed functions are available elsewhere – containers and vector provide them for their types, and ilist provides indexed functions for lists).You want a library with a clean, understandable implementation (in which case you're looking for lens-simple).
As already mentioned, if you're writing an application which uses lenses more extensively, look at microlens-platform – it combines features of most other microlens packages (microlens-mtl, microlens-th, microlens-ghc).
If you want to export getters or folds and don't mind the contravariant dependency, please consider using microlens-contra.
If you haven't ever used lenses before, read this tutorial. (It's for lens, but it applies to microlens just as well.)
Note that microlens has no dependencies starting from GHC 7.10 (base-4.8). Prior to that, it depends on transformers-0.2 or above.
Changes
0.4.13.0
- Added
_Show,worded, andlined.
0.4.12.0
- Added instance
Ixed (NonEmpty a)for GHC >= 8.
0.4.11.3
- Exported a
coercecompatibility shim fromLens.Micro.Internal.
0.4.11.2
- Fixed compilation on GHC 8.8 (thanks to @vmchale).
0.4.11.1
- Reverted marking
Lens.Micro.InternalasTrustworthy, see #122.
0.4.11
- Added fixity declarations for
+~and-~(thanks to Francesco Ariis). - Added
rewriteOfandtransformOf(thanks to @quasicomputational). - Added an instance
Each (Either a a) (Either b b) a b, followinglens’s suit. - Marked
Lens.Micro.InternalasTrustworthystarting from GHC 7.8.
0.4.10
- Added
+~and-~. - Marked
#.and.#withINLINE.
0.4.9.1
- Reexported
<&>fromData.Functor(on recent versions ofbase).
0.4.9
- Added
<>~. - Added fixities for
<%~,<<%~,<<.~.
0.4.8.3
- Fixed compilation on GHC 8.4.
0.4.8.2
Skipped (the tarball got corrupted).
0.4.8.1
- Added
HasCallStackfor some partial functions.
0.4.8.0
- Added
forOf_andforOf. - Added an instance for
Each (NonEmpty a)(available starting from GHC 8).
0.4.7.0
- Fixed the Haddock crash on GHC 8 by removing default method implementations (
each = traverseandix = ixAt). If you had custom instances ofIxedorEachwhich relied on default methods, they’d stop working.
0.4.6.0
- Added
traverseOfandtraverseOf_. - Changed fixities of
#.and.#to the ones in the profunctors package. Those operators are only available fromLens.Micro.Internal, so this shouldn’t affect most users.
0.4.5.0
- Added
<&>(which makes lens creation easier).
0.4.4.3
- Fixed markup in the .cabal file.
- Added descriptions of other packages to
Lens.Micro.
0.4.4.2
- More changes to make microlens-platform more prominent.
0.4.4.1
- Pointed to microlens-platform in the synopsis.
0.4.4.0
- Added
mapAccumLOf.
0.4.3.0
- Added
?~.
0.4.2.1
- Added forgotten copyright/authorship information.
0.4.2.0
- Added
singular.
0.4.1.0
- Added
strictandlazy.
0.4.0.1
- Fixed a bug that wasn’t letting the package compile with GHC 8.0 (see issue #63).
0.4.0.0
- Added
folding. - Renamed
GetterandFoldtoSimpleGetterandSimpleFoldand put them intoLens.Micro. GenuineGetterandFoldare available in microlens-contra. - Replaced
Applicative (Const r)constraints withMonoid rbecause it’s the same thing but easier to understand.
0.3.5.1
- Backported the fix for the bug that wasn’t letting the package compile with GHC 8.0 (see issue #63).
0.3.5.0
- Added
Lens.Micro.Extraswithview,preview,Getter, andFold. Now you no longer need microlens-mtl if the only thing you need from it isview.
0.3.4.1
- Changed the description of the package from “A tiny part of the lens library which you can depend upon” to “A tiny part of the lens library with no dependencies” because the previous one was ambiguous (I admit I kinda liked that ambiguity, though).
0.3.4.0
- Added
non.
0.3.3.0
- Added
filtered. - Added Safe Haskell pragmas.
0.3.2.0
- Added
toListOfback. - Added
to.
0.3.1.0
- Added
LensLikeandLensLike'. - Added
failing.
0.3.0.0
- Moved
Lens.Micro.ClassesintoLens.Micro.Internal. - Added
<%~,<<%~,<<.~. - Added
_head,_tail,_init,_last.
0.2.0.0
- Removed
toListOf. - Removed
+~,-~,*~,//~and theLens.Micro.Extrasmodule.
0.1.5.0
- Added
ixandat. - Added
traversed. - Moved some things into
Lens.Micro.Internal. - Bumped base version.
0.1.3.0
- Moved some things into
Lens.Micro.TypeandLens.Micro.Classes. EachandField*aren’t exported byLens.Micronow.
0.1.2.0
- Added
each.
0.1.1.0
- Added
ASetter', which is useful because we can’t provide realSetterandSetter'.
0.1.0.0
First release.