-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Basic lens type and functions -- -- Necessary type and functions for basic lens work. -- -- Handy to depend on for libraries and general light-weight use, -- including PITA environments, old GHCs and non-GHC implementations with -- Rank-N type support. Depends on only on base. @package basic-lens @version 0.0.2 -- | Basic lens type and functions. -- -- The lens package should be a drop-in replacement for this. module Control.Lens.Basic -- | Purpose -- -- A value of type Lens s t a b provides the following: -- --
-- type Lens s t a b = (a -> b) -> (s -> t) ---- -- But it is left generic for forward compatibilty with the lens package. -- -- Example -- --
-- λ> data Person = Person { personChar :: Char, personAge :: Int } deriving Show
-- λ> view $(field 'personChar) (Person a 10)
-- a
-- λ> over $(field 'personAge) (*2) (Person a 10)
-- Person {personChar = a, personAge = 20}
-- λ>
--
--
-- Laws
--
-- 1) Get-Put: You get back what you put in.
--
-- -- view l (set l v s) ≡ v ---- -- 2) Put-Get: Putting back what you got doesn't change anything. -- --
-- set l (view l s) s ≡ s ---- -- 3) Put-Put: Setting is idempotent. -- --
-- set l v (set l v s) ≡ set l v s --type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t) -- | Get the a inside the s. view :: Lens s t a b -> s -> a -- | Set the a inside the s, optionally changing the -- types to b and t. set :: Lens s t a b -> b -> s -> t -- | Modify the a inside the s, optionally changing the -- types to b and t. over :: Lens s t a b -> (a -> b) -> s -> t -- | Make a lens from a field name. -- -- Example: over $(field 'foo) (*2) field :: Name -> Q Exp instance GHC.Base.Functor Control.Lens.Basic.Id