A tiny part of the lens library with no dependencies


Version on this page:
LTS Haskell 19.13:
Stackage Nightly 2022-06-30:
Latest on Hackage:

See all snapshots microlens appears in

BSD-3-Clause licensed by Edward Kmett, Artyom
Maintained by Artyom
This version can be pinned in stack with:microlens-,3586

Module documentation for

This 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.

Use this library:

  • if you want to define lenses or traversals in your own library, but don't want to depend on lens

  • if you are new to lenses and want a small library to play with, but don't want to use something “inferior” or have to relearn things when/if you switch to lens

Don't use this library:

  • if you need Isos, Prisms, indexed traversals, or actually anything else which isn't defined here (tho some indexed functions are available elsewhere – containers and vector provide them for their types, and ilist provides indexed functions for lists)

  • if you want a library with a clean, understandable implementation (in which case you're looking for lens-simple)

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.

There's a longer readme on Github, you should read it if you're interested about using this library.

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 has to depend on transformers-0.2 or above.


  • Added mapAccumLOf.

  • Added ?~.

  • Added forgotten copyright/authorship information.

  • Added singular.

  • Added strict and lazy.

  • Fixed a bug that wasn’t letting the package compile with GHC 8.0 (see issue #63).

  • Added folding.
  • Renamed Getter and Fold to SimpleGetter and SimpleFold and put them into Lens.Micro. Genuine Getter and Fold are available in microlens-contra.
  • Replaced Applicative (Const r) constraints with Monoid r because it’s the same thing but easier to understand.

  • Backported the fix for the bug that wasn’t letting the package compile with GHC 8.0 (see issue #63).

  • Added Lens.Micro.Extras with view, preview, Getter, and Fold. Now you no longer need microlens-mtl if the only thing you need from it is view.

  • 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, tho).

  • Added non.

  • Added filtered.
  • Added Safe Haskell pragmas.

  • Added toListOf back.
  • Added to.

  • Added LensLike and LensLike'.
  • Added failing.

  • Moved Lens.Micro.Classes into Lens.Micro.Internal.
  • Added <%~, <<%~, <<.~.
  • Added _head, _tail, _init, _last.

  • Removed toListOf.
  • Removed +~, -~, *~, //~ and the Lens.Micro.Extras module.

  • Added ix and at.
  • Added traversed.
  • Moved some things into Lens.Micro.Internal.
  • Bumped base version.

  • Moved some things into Lens.Micro.Type and Lens.Micro.Classes.
  • Each and Field* aren’t exported by Lens.Micro now.

  • Added each.

  • Added ASetter', which is useful because we can’t provide real Setter and Setter'.

First release.