HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelens-5.3.5Haskell2010

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.

  • 3 values
  • Packagelens-5.3.5
  • 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?

valueprismSum
  1. :: APrism s t a b
  2. -> APrism s t c d
  3. -> Prism s t (Either a c) (Either b d)
#

A dual of lensProduct: a prism sum.

The law

preview l (review l b) ≡ Just b

breaks with

Example2 expressions
let badPrism :: Prism' (Maybe Char) (Either Char Char); badPrism = prismSum _Just _Justpreview badPrism (review badPrism (Right 'x'))Just (Left 'x')

We put in Right value, but get back Left.

Are you looking for without?