packages feed

basic-lens (empty) → 0.0.0

raw patch · 4 files changed

+137/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ LICENSE view
@@ -0,0 +1,24 @@+Copyright (c) 2015, basic-lens+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:+    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.+    * Redistributions in binary form must reproduce the above copyright+      notice, this list of conditions and the following disclaimer in the+      documentation and/or other materials provided with the distribution.+    * Neither the name of basic-lens nor the+      names of its contributors may be used to endorse or promote products+      derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ basic-lens.cabal view
@@ -0,0 +1,23 @@+name:                basic-lens+version:             0.0.0+synopsis:            Basic Lens type and functions+description:         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.+license:             BSD3+license-file:        LICENSE+author:              Chris Done+maintainer:          chrisdone@gmail.com+copyright:           2014 Edward Kmett, Nikita Volkov, Chris Done+category:            Development+build-type:          Simple+cabal-version:       >=1.8++library+  hs-source-dirs:    src/+  ghc-options:       -Wall -O2+  exposed-modules:   Control.Lens.Basic+  build-depends:     base >= 4 && <5
+ src/Control/Lens/Basic.hs view
@@ -0,0 +1,88 @@+{-# LANGUAGE RankNTypes #-}++-- | Basic lens type and functions.+--+-- The lens package should be a drop-in replacement for this.+--++module Control.Lens.Basic+  (-- * Lens type+   Lens+   -- * Functions+  ,view+  ,set+  ,over)+  where++import Control.Applicative++-- |+--+-- __Purpose__+--+-- A value of type @Lens s t a b@ provides the following:+--+-- * A reference into the structure @s@ to read and update the value @a@ inside it.+-- * The possibility to change the type of @s@ to @t@ and the type of @a@ to @b@.+--+-- __The @Functor@ constraint__+--+-- 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+-- and therefore the above type is equivalent to:+--+-- @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 Char Int deriving Show+-- λ> let _age f (Person x a) = fmap (\\b -> Person x b) (f a)+-- λ> view _age (Person 'a' 10)+-- 10+-- λ> over _age (+1) (Person 'a' 10)+-- Person 'a' 11+-- λ> set _age 100 (Person 'a' 10)+-- Person 'a' 100+-- λ>+-- @+--+-- __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)++-- Internal id functor.+newtype Id a = Id { runId :: a }++-- | Could use @DeriveFunctor@ here but that's not portable.+instance Functor Id where fmap f = Id . f . runId++-- | Get the @a@ inside the @s@.+view :: Lens s t a b -> s -> a+view l = getConst . l Const++-- | Modify the @a@ inside the @s@, optionally changing the types to+-- @b@ and @t@.+over :: Lens s t a b -> (a -> b) -> s -> t+over l f = runId . l (Id . f)++-- | Set the @a@ inside the @s@, optionally changing the types to @b@+-- and @t@.+set :: Lens s t a b -> b -> s -> t+set l a = runId . l (Id . const a)