basic-lens 0.0.0 → 0.0.1
raw patch · 2 files changed
+18/−4 lines, 2 filesdep +template-haskellPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: template-haskell
API changes (from Hackage documentation)
- Control.Lens.Basic: instance Functor Id
+ Control.Lens.Basic: instance GHC.Base.Functor Control.Lens.Basic.Id
Files
- basic-lens.cabal +3/−3
- src/Control/Lens/Basic.hs +15/−1
basic-lens.cabal view
@@ -1,6 +1,6 @@ name: basic-lens-version: 0.0.0-synopsis: Basic Lens type and functions+version: 0.0.1+synopsis: Basic lens type and functions description: Necessary type and functions for basic lens work. . Handy to depend on for libraries and general@@ -20,4 +20,4 @@ hs-source-dirs: src/ ghc-options: -Wall -O2 exposed-modules: Control.Lens.Basic- build-depends: base >= 4 && <5+ build-depends: base >= 4 && <5, template-haskell
src/Control/Lens/Basic.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE RankNTypes #-}+{-# LANGUAGE TemplateHaskell #-} -- | Basic lens type and functions. --@@ -15,6 +16,7 @@ where import Control.Applicative+import Language.Haskell.TH -- | --@@ -29,7 +31,7 @@ -- -- Operations may do something more interesting inside the `f` -- functor. For the purpose of this module and package, all the--- functions below ('view', 'over', 'set') use the identity functor+-- functions below ('view', 'over', 'set') use a no-op functor -- and therefore the above type is equivalent to: -- -- @type Lens s t a b = (a -> b) -> (s -> t)@@@ -86,3 +88,15 @@ -- and @t@. set :: Lens s t a b -> b -> s -> t set l a = runId . l (Id . const a)++-- | Make a lens from a field name.+--+-- Example: @over $(field 'foo) (*2)@+field :: Name -> Q Exp+field name = do+ [|\f r ->+ fmap+ $(lamE+ [varP (mkName "a")]+ (recUpdE (varE (mkName "r")) [return (name, VarE (mkName "a"))]))+ (f ($(varE name) r))|]