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

A Review is a type-restricted form of a Prism that can only be used for writing back via re, review, reuse.

  • 2 types
  • 2 classes
  • 10 values
  • Packagelens-5.3.5
  • Exports14
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceReview.hs

Reviewing

14 declarations
valuereview :: MonadReader b m => AReview t b -> m t
#

This can be used to turn an Control.Lens.Iso.Iso or Prism around and view a value (or the current environment) through it the other way.

review ≡ view . re
review . unto ≡ id
Example1 expression
review _Left "mustard"Left "mustard"
Example1 expression
review (unto succ) 56

Usually review is used in the (->) Monad with a Prism or Control.Lens.Iso.Iso, in which case it may be useful to think of it as having one of these more restricted type signatures:

review :: Iso' s a   -> a -> s
review :: Prism' s a -> a -> s

However, when working with a Monad transformer stack, it is sometimes useful to be able to review the current environment, in which case it may be beneficial to think of it as having one of these slightly more liberal type signatures:

review :: MonadReader a m => Iso' s a   -> m s
review :: MonadReader a m => Prism' s a -> m s
valuereviews :: MonadReader b m => AReview t b -> (t -> r) -> m r
#

This can be used to turn an Control.Lens.Iso.Iso or Prism around and view a value (or the current environment) through it the other way, applying a function.

reviews ≡ views . re
reviews (unto f) g ≡ g . f
Example1 expression
reviews _Left isRight "mustard"False
Example1 expression
reviews (unto succ) (*2) 38

Usually this function is used in the (->) Monad with a Prism or Control.Lens.Iso.Iso, in which case it may be useful to think of it as having one of these more restricted type signatures:

reviews :: Iso' s a   -> (s -> r) -> a -> r
reviews :: Prism' s a -> (s -> r) -> a -> r

However, when working with a Monad transformer stack, it is sometimes useful to be able to review the current environment, in which case it may be beneficial to think of it as having one of these slightly more liberal type signatures:

reviews :: MonadReader a m => Iso' s a   -> (s -> r) -> m r
reviews :: MonadReader a m => Prism' s a -> (s -> r) -> m r
value(#) :: AReview t b -> b -> t
#

An infix alias for review.

unto f # x ≡ f x
l # x ≡ x ^. re l

This is commonly used when using a Prism as a smart constructor.

Example1 expression
_Left # 4Left 4

But it can be used for any Prism

Example1 expression
base 16 # 123"7b"
(#) :: Iso'      s a -> a -> s
(#) :: Prism'    s a -> a -> s
(#) :: Review    s a -> a -> s
(#) :: Equality' s a -> a -> s
classclass (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where
#

A bifunctor is a type constructor that takes two type arguments and is a functor in both arguments. That is, unlike with Functor, a type constructor such as Either does not need to be partially applied for a Bifunctor instance, and the methods in this class permit mapping functions over the Left value or the Right value, or both at the same time.

Formally, the class Bifunctor represents a bifunctor from Hask -> Hask.

Intuitively it is a bifunctor where both the first and second arguments are covariant.

The class definition of a Bifunctor p uses the QuantifiedConstraints language extension to quantify over the first type argument a in its context. The context requires that p a must be a Functor for all a. In other words a partially applied Bifunctor must be a Functor. This makes Functor a superclass of Bifunctor such that a function with a Bifunctor constraint may use fmap in its implementation. Functor has been a quantified superclass of Bifunctor since base-4.18.0.0.

You can define a Bifunctor by either defining bimap or by defining both first and second. The second method must agree with fmap:

second ≡ fmap

From this it follows that:

second id ≡ id

If you supply bimap, you should ensure that:

bimap id id ≡ id

If you supply first and second, ensure:

first id ≡ id
second id ≡ id

If you supply both, you should also ensure:

bimap f g ≡ first f . second g

These ensure by parametricity:

bimap  (f . g) (h . i) ≡ bimap f h . bimap g i
first  (f . g) ≡ first  f . first  g
second (f . g) ≡ second f . second g

Methods

  • bimap :: (a -> b) -> (c -> d) -> p a c -> p b d

    Map over both arguments at the same time.

    bimap f g ≡ first f . second g
    Examples
    Example1 expression
    bimap toUpper (+1) ('j', 3)('J',4)
    Example1 expression
    bimap toUpper (+1) (Left 'j')Left 'J'
    Example1 expression
    bimap toUpper (+1) (Right 3)Right 4
Instances30Bifunctor, …