HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulelens-5.3.6Haskell2010

Control.Lens.Unsound

One commonly asked question is: can we combine two lenses, Lens' a b and Lens' a c into Lens' a (b, c). This is fair thing to ask, but such operation is unsound in general. See lensProduct.

Synopsis
  • Packagelens-5.3.6
  • Exports3
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceUnsound.hs
valuelensProduct :: ALens' s a -> ALens' s b -> Lens' s (a, b)

A lens product. There is no law-abiding way to do this in general. Result is only a valid Lens if the input lenses project disjoint parts of the structure s. Otherwise "you get what you put in" law

view l (set l v s) ≡ v

is violated by

Example2 expressions
let badLens :: Lens' (Int, Char) (Int, Int); badLens = lensProduct _1 _1view badLens (set badLens (1,2) (3,'x'))(2,2)

but we should get (1,2).

Are you looking for alongside?