Hoogle Search
Within LTS Haskell 24.36 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
module Control.Lens.Internal.
Profunctor No documentation available.
class
Profunctor (p :: Type -> Type -> Type)lens Control.Lens.Iso Formally, the class Profunctor represents a profunctor from Hask -> Hask. Intuitively it is a bifunctor where the first argument is contravariant and the second argument is covariant. You can define a Profunctor by either defining dimap or by defining both lmap and rmap. If you supply dimap, you should ensure that:
dimap id id ≡ id
If you supply lmap and rmap, ensure:lmap id ≡ id rmap id ≡ id
If you supply both, you should also ensure:dimap f g ≡ lmap f . rmap g
These ensure by parametricity:dimap (f . g) (h . i) ≡ dimap g h . dimap f i lmap (f . g) ≡ lmap g . lmap f rmap (f . g) ≡ rmap f . rmap g
-
The name "plate" stems originally from "boilerplate", which was the term used by the "Scrap Your Boilerplate" papers, and later inherited by Neil Mitchell's "Uniplate". https://www.cs.york.ac.uk/fp/darcs/uniplate/uniplate.htm The combinators in here are designed to be compatible with and subsume the uniplate API with the notion of a Traversal replacing a uniplate or biplate. By implementing these combinators in terms of plate instead of uniplate additional type safety is gained, as the user is no longer responsible for maintaining invariants such as the number of children they received. Note: The Biplate is deliberately excluded from the API here, with the intention that you replace them with either explicit traversals, or by using the On variants of the combinators below with biplate from Data.Data.Lens. As a design, it forced the user into too many situations where they had to choose between correctness and ease of use, and it was brittle in the face of competing imports. The sensible use of these combinators makes some simple assumptions. Notably, any of the On combinators are expecting a Traversal, Setter or Fold to play the role of the biplate combinator, and so when the types of the contents and the container match, they should be the id Traversal, Setter or Fold. It is often beneficial to use the combinators in this module with the combinators from Data.Data.Lens or GHC.Generics.Lens to make it easier to automatically derive definitions for plate, or to derive custom traversals.
-
lens Control.Lens.Plated A Plated type is one where we know how to extract its immediate self-similar children. Example 1:
import Control.Applicative import Control.Lens import Control.Lens.Plated import Data.Data import Data.Data.Lens (uniplate)
data Expr = Val Int | Neg Expr | Add Expr Expr deriving (Eq,Ord,Show,Read,Data)
instance Plated Expr where plate f (Neg e) = Neg <$> f e plate f (Add a b) = Add <$> f a <*> f b plate _ a = pure a
orinstance Plated Expr where plate = uniplate
Example 2:import Control.Applicative import Control.Lens import Control.Lens.Plated import Data.Data import Data.Data.Lens (uniplate)
data Tree a = Bin (Tree a) (Tree a) | Tip a deriving (Eq,Ord,Show,Read,Data)
instance Plated (Tree a) where plate f (Bin l r) = Bin <$> f l <*> f r plate _ t = pure t
orinstance Data a => Plated (Tree a) where plate = uniplate
Note the big distinction between these two implementations. The former will only treat children directly in this tree as descendents, the latter will treat trees contained in the values under the tips also as descendants! When in doubt, pick a Traversal and just use the various ...Of combinators rather than pollute Plated with orphan instances! If you want to find something unplated and non-recursive with biplate use the ...OnOf variant with ignored, though those usecases are much better served in most cases by using the existing Lens combinators! e.g.toListOf biplate ≡ universeOnOf biplate ignored
This same ability to explicitly pass the Traversal in question is why there is no analogue to uniplate's Biplate. Moreover, since we can allow custom traversals, we implement reasonable defaults for polymorphic data types, that only traverse into themselves, and not their polymorphic arguments. -
No documentation available.
-
lens Control.Lens.Prism No documentation available.
-
lens Control.Lens.Prism A Prism l is a Traversal that can also be turned around with re to obtain a Getter in the opposite direction. There are three laws that a Prism should satisfy: First, if I re or review a value with a Prism and then preview or use (^?), I will get it back:
preview l (review l b) ≡ Just b
Second, if you can extract a value a using a Prism l from a value s, then the value s is completely described by l and a:preview l s ≡ Just a ⟹ review l a ≡ s
Third, if you get non-match t, you can convert it result back to s:matching l s ≡ Left t ⟹ matching l t ≡ Left s
The first two laws imply that the Traversal laws hold for every Prism and that we traverse at most 1 element:lengthOf l x <= 1
It may help to think of this as an Iso that can be partial in one direction. Every Prism is a valid Traversal. Every Iso is a valid Prism. For example, you might have a Prism' Integer Natural allows you to always go from a Natural to an Integer, and provide you with tools to check if an Integer is a Natural and/or to edit one if it is.nat :: Prism' Integer Natural nat = prism toInteger $ \ i -> if i < 0 then Left i else Right (fromInteger i)
Now we can ask if an Integer is a Natural.>>> 5^?nat Just 5
>>> (-5)^?nat Nothing
We can update the ones that are:>>> (-3,4) & both.nat *~ 2 (-3,8)
And we can then convert from a Natural to an Integer.>>> 5 ^. re nat -- :: Natural 5
Similarly we can use a Prism to traverse the Left half of an Either:>>> Left "hello" & _Left %~ length Left 5
or to construct an Either:>>> 5^.re _Left Left 5
such that if you query it with the Prism, you will get your original input back.>>> 5^.re _Left ^? _Left Just 5
Another interesting way to think of a Prism is as the categorical dual of a Lens -- a co-Lens, so to speak. This is what permits the construction of outside. Note: Composition with a Prism is index-preserving. type
Prism' s a = Prism s s a alens Control.Lens.Prism module Control.Lens.
Profunctor This module provides conversion functions between the optics defined in this library and Profunctor-based optics. The goal of these functions is to provide an interoperability layer between the two styles of optics, and not to reimplement all the library in terms of Profunctor optics.
Prism :: Prism s t a b -> ReifiedPrism s t a blens Control.Lens.Reified No documentation available.