packages feed

data-accessor 0.2.1.7 → 0.2.1.8

raw patch · 7 files changed

+128/−106 lines, 7 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

data-accessor.cabal view
@@ -1,12 +1,15 @@ Name:             data-accessor-Version:          0.2.1.7+Version:          0.2.1.8 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>, Luke Palmer <lrpalmer@gmail.com> Maintainer:       Henning Thielemann <haskell@henning-thielemann.de> Homepage:         http://www.haskell.org/haskellwiki/Record_access-Package-URL:      http://code.haskell.org/data-accessor/core/ Category:         Data+-- Default-Language: Haskell98+Cabal-Version:    >=1.6+Build-Type:       Simple+Tested-With:      GHC==6.4.1, GHC==6.8.2, GHC==6.10.4, GHC==6.12.3, GHC==7.0.1, JHC==0.7.3 Synopsis:         Utilities for accessing and manipulating fields of records Description:   In Haskell 98 the name of a record field@@ -48,6 +51,9 @@   rather than plain @get@ functions.   For now, the package @data-accessor-template@ provides Template Haskell functions   for automated generation of 'Data.Acesssor.Accessor's.+  See also the other @data-accessor@ packages+  that provide an Accessor interface to other data types.+  The package @enumset@ provides accessors to bit-packed records.   .   For similar packages see @lenses@ and @fclabel@.   A related concept are editors@@ -58,20 +64,20 @@   whereas an accessor can only change a single function value,   say, it can change @f 0 = 1@ to @f 0 = 2@.   This way, editors can even change the type of a record or a function.-  An Arrow instance can be define for editors,+  An Arrow instance can be defined for editors,   but for accessors only a Category instance is possible ('(.)' method).   The reason is the @arr@ method of the @Arrow@ class,   that conflicts with the two-way nature (set and get) of accessors.--- Portability:      Haskell98-Cabal-Version:    >=1.2-Tested-With:      GHC==6.4.1, GHC==6.8.2, GHC==6.10.4, GHC==7.0.1, JHC==0.7.3-Build-Type:       Simple  Extra-Source-Files:   RegExp   src-3/Data/Accessor/Private.hs   src-4/Data/Accessor/Private.hs +Source-Repository head+  Type:        darcs+  Location:    http://code.haskell.org/data-accessor/core/+ Flag category   description: Check whether Arrow class is split into Arrow and Category. @@ -87,7 +93,7 @@       containers >=0.1 && <0.5     If flag(category)       Hs-Source-Dirs: src-4-      Build-Depends: base >= 4 && <6+      Build-Depends: base >= 4 && <5     Else       Hs-Source-Dirs: src-3       Build-Depends: base >= 2 && <4@@ -112,3 +118,4 @@   Other-Modules:     Data.Accessor.Example     Data.Accessor.Private+    Data.Accessor.MonadStatePrivate
src-3/Data/Accessor/Private.hs view
@@ -1,19 +1,23 @@ module Data.Accessor.Private where  {- |-The access functions we propose, look very similar to those-needed for List.mapAccumL (but parameter order is swapped) and State monad.-They get the new value of the field and the record-and return the old value of the field and the record with the updated field.+The accessor function we use,+has a record value as first argument+and returns the content of a specific record field+and a function that allows to overwrite that field with a new value.++In former version of a package+we used a function that resembled the state monad.+However this required to use an 'undefined'+in the implementation of the @get@ function. -}-newtype T r a  =  Cons {decons :: a -> r -> (a, r)}+newtype T r a  =  Cons {decons :: r -> (a, a -> r)}  compose :: T a b -> T b c -> T a c-compose f g = Cons $ \ cNew aOld ->-   let (bOld, aNew) = decons f bNew aOld-       (cOld, bNew) = decons g cNew bOld-   in  (cOld, aNew)+compose f g = Cons $ \ aOld ->+   let (bOld, aSetB) = decons f aOld+       (cOld, bSetC) = decons g bOld+   in  (cOld, aSetB . bSetC)  self :: T r r-self = Cons $ \ai ri -> (ri, ai)-+self = Cons $ \r -> (r, id)
src-4/Data/Accessor/Private.hs view
@@ -4,21 +4,26 @@   {- |-The access functions we propose, look very similar to those-needed for List.mapAccumL (but parameter order is swapped) and State monad.-They get the new value of the field and the record-and return the old value of the field and the record with the updated field.+The accessor function we use,+has a record value as first argument+and returns the content of a specific record field+and a function that allows to overwrite that field with a new value.++In former version of a package+we used a function that resembled the state monad.+However this required to use an 'undefined'+in the implementation of the @get@ function. -}-newtype T r a  =  Cons {decons :: a -> r -> (a, r)}+newtype T r a  =  Cons {decons :: r -> (a, a -> r)}  compose :: T a b -> T b c -> T a c-compose f g = Cons $ \ cNew aOld ->-   let (bOld, aNew) = decons f bNew aOld-       (cOld, bNew) = decons g cNew bOld-   in  (cOld, aNew)+compose f g = Cons $ \ aOld ->+   let (bOld, aSetB) = decons f aOld+       (cOld, bSetC) = decons g bOld+   in  (cOld, aSetB . bSetC)  self :: T r r-self = Cons $ \ai ri -> (ri, ai)+self = Cons $ \r -> (r, id)   instance C.Category T where
src/Data/Accessor.hs view
@@ -1,7 +1,6 @@ {- | This module provides a simple abstract data type for-a piece of a data stucture that can be read from and-written to.+a piece of a data stucture that can be read from and written to. In contrast to "Data.Accessor.Basic" it is intended for unqualified import. -} module Data.Accessor@@ -13,7 +12,7 @@ where  import qualified Data.Accessor.Basic as Accessor-import qualified Data.Accessor.MonadState as State+import qualified Data.Accessor.MonadStatePrivate as State import Control.Monad.Trans.State (StateT, )  -- |An @Accessor r a@ is an object that encodes how to@@ -68,6 +67,8 @@ Accessor composition the other direction.  > (<.) = flip (.>)++You may also use the @(.)@ operator from Category class. -} (<.) :: Accessor b c -> Accessor a b -> Accessor a c (<.) = (Accessor.<.)
src/Data/Accessor/Basic.hs view
@@ -21,11 +21,10 @@  fromSetGet :: (a -> r -> r) -> (r -> a) -> T r a fromSetGet setF getF =-   Cons $ \x r -> (getF r, setF x r)+   Cons $ \r -> (getF r, flip setF r)  fromLens :: (r -> (a, a -> r)) -> T r a-fromLens lens =-   Cons $ \ x r -> let (y,f) = lens r in (y, f x)+fromLens = Cons  {- | If an object is wrapped in a @newtype@,@@ -87,7 +86,7 @@  {- | Set the value of a field. -} set :: T r a -> a -> r -> r-set f x = snd . decons f x+set f a r = snd (decons f r) a   infixr 5 ^=, ^:@@ -125,7 +124,7 @@  {- | Get the value of a field. -} get :: T r a -> r -> a-get f = fst . decons f undefined+get f = fst . decons f  infixl 8 ^. @@ -141,8 +140,8 @@ {- | Transform the value of a field by a function. -} modify :: T r a -> (a -> a) -> (r -> r) modify f g rOld =-   let (a,rNew) = decons f (g a) rOld-   in  rNew+   let (a,rSetA) = decons f rOld+   in  rSetA (g a)   {- |@@ -185,6 +184,8 @@ Accessor composition the other direction.  > (<.) = flip (.>)++You may also use the @(.)@ operator from Category class. -} (<.) :: T b c -> T a b -> T a c (<.) = flip A.compose
src/Data/Accessor/MonadState.hs view
@@ -1,72 +1,7 @@ {- | Access helper functions in a State monad -} module Data.Accessor.MonadState    {-# DEPRECATED "please use Data.Accessor.Monad.Trans.State from data-accessor-transformers" #-}+   (module Data.Accessor.MonadStatePrivate)    where -import qualified Data.Accessor.Basic as Accessor-import qualified Control.Monad.Trans.State as State-import qualified Control.Monad.Trans.Class as Trans-import Control.Monad.Trans.State (State, runState, StateT(runStateT), )---- * accessors in the form of actions in the state monad--set :: Monad m => Accessor.T r a -> a -> StateT r m ()-set f x = State.modify (Accessor.set f x)--get :: Monad m => Accessor.T r a -> StateT r m a-get f = State.gets (Accessor.get f)--modify :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m ()-modify f g = State.modify (Accessor.modify f g)--{- |-Modify a record element and return its old value.--}-getAndModify :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m a-getAndModify f g =-   do x <- get f-      modify f g-      return x--{- |-Modify a record element and return its new value.--}-modifyAndGet :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m a-modifyAndGet f g =-   do modify f g-      get f----infix 1 %=, %:--{- |-Infix variant of 'set'.--}-(%=) :: Monad m => Accessor.T r a -> a -> StateT r m ()-(%=) = set--{- |-Infix variant of 'modify'.--}-(%:) :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m ()-(%:) = modify------ * lift a state monadic accessor to an accessor of a parent record--lift :: Monad m => Accessor.T r s -> State s a -> StateT r m a-lift f m =-   do s0 <- get f-      let (a,s1) = runState m s0-      set f s1-      return a--liftT :: (Monad m) =>-   Accessor.T r s -> StateT s m a -> StateT r m a-liftT f m =-   do s0 <- get f-      (a,s1) <- Trans.lift $ runStateT m s0-      set f s1-      return a+import Data.Accessor.MonadStatePrivate
+ src/Data/Accessor/MonadStatePrivate.hs view
@@ -0,0 +1,69 @@+module Data.Accessor.MonadStatePrivate where++import qualified Data.Accessor.Basic as Accessor+import qualified Control.Monad.Trans.State as State+import qualified Control.Monad.Trans.Class as Trans+import Control.Monad.Trans.State (State, runState, StateT(runStateT), )++-- * accessors in the form of actions in the state monad++set :: Monad m => Accessor.T r a -> a -> StateT r m ()+set f x = State.modify (Accessor.set f x)++get :: Monad m => Accessor.T r a -> StateT r m a+get f = State.gets (Accessor.get f)++modify :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m ()+modify f g = State.modify (Accessor.modify f g)++{- |+Modify a record element and return its old value.+-}+getAndModify :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m a+getAndModify f g =+   do x <- get f+      modify f g+      return x++{- |+Modify a record element and return its new value.+-}+modifyAndGet :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m a+modifyAndGet f g =+   do modify f g+      get f++++infix 1 %=, %:++{- |+Infix variant of 'set'.+-}+(%=) :: Monad m => Accessor.T r a -> a -> StateT r m ()+(%=) = set++{- |+Infix variant of 'modify'.+-}+(%:) :: Monad m => Accessor.T r a -> (a -> a) -> StateT r m ()+(%:) = modify++++-- * lift a state monadic accessor to an accessor of a parent record++lift :: Monad m => Accessor.T r s -> State s a -> StateT r m a+lift f m =+   do s0 <- get f+      let (a,s1) = runState m s0+      set f s1+      return a++liftT :: (Monad m) =>+   Accessor.T r s -> StateT s m a -> StateT r m a+liftT f m =+   do s0 <- get f+      (a,s1) <- Trans.lift $ runStateT m s0+      set f s1+      return a