data-accessor-mtl-0.2.0.5/0000755000175000001440000000000014361046116016170 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/data-accessor-mtl.cabal0000644000175000001440000000210614361046116022456 0ustar00thielemausers00000000000000Name: data-accessor-mtl Version: 0.2.0.5 License: BSD3 License-File: LICENSE Author: Henning Thielemann Maintainer: Henning Thielemann Homepage: http://www.haskell.org/haskellwiki/Record_access Category: Data Cabal-Version: >=1.10 Build-Type: Simple Tested-With: GHC==6.8.2, GHC==6.10.4, GHC==6.12.3 Tested-With: GHC==7.0.1, GHC==7.4.1 Synopsis: Use Accessor to access state in mtl State monad class Description: Use Accessor to access state in mtl State monad class Source-Repository this Tag: 0.2.0.5 Type: darcs Location: http://code.haskell.org/data-accessor/mtl/ Source-Repository head Type: darcs Location: http://code.haskell.org/data-accessor/mtl/ Library Build-Depends: data-accessor >=0.2 && <0.4, mtl >=1.0 && <2.4, base >=1.0 && <5 Hs-Source-Dirs: src Default-Language: Haskell98 GHC-Options: -Wall Exposed-Modules: Data.Accessor.Monad.MTL.State data-accessor-mtl-0.2.0.5/Setup.lhs0000644000175000001440000000011514361046116017775 0ustar00thielemausers00000000000000#! /usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain data-accessor-mtl-0.2.0.5/LICENSE0000644000175000001440000000261214361046116017176 0ustar00thielemausers00000000000000Redistribution 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 the ; 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. data-accessor-mtl-0.2.0.5/src/0000755000175000001440000000000014361046116016757 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/src/Data/0000755000175000001440000000000014361046116017630 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/src/Data/Accessor/0000755000175000001440000000000014361046116021372 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/src/Data/Accessor/Monad/0000755000175000001440000000000014361046116022430 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/src/Data/Accessor/Monad/MTL/0000755000175000001440000000000014361046116023064 5ustar00thielemausers00000000000000data-accessor-mtl-0.2.0.5/src/Data/Accessor/Monad/MTL/State.hs0000644000175000001440000000362714361046116024510 0ustar00thielemausers00000000000000{- | Access helper functions in the State monad class -} module Data.Accessor.Monad.MTL.State where import qualified Data.Accessor.Basic as Accessor import qualified Control.Monad.State as State import qualified Control.Monad.Trans as Trans import Control.Monad.State (MonadState, State, runState, StateT(runStateT), ) import Control.Monad.Trans (MonadTrans, ) -- * accessors in the form of actions in the state monad set :: MonadState r m => Accessor.T r a -> a -> m () set f x = State.modify (Accessor.set f x) get :: MonadState r m => Accessor.T r a -> m a get f = State.gets (Accessor.get f) modify :: MonadState r m => Accessor.T r a -> (a -> a) -> m () modify f g = State.modify (Accessor.modify f g) {- | Modify a record element and return its old value. -} getAndModify :: MonadState r m => Accessor.T r a -> (a -> a) -> m a getAndModify f g = do x <- get f modify f g return x {- | Modify a record element and return its new value. -} modifyAndGet :: MonadState r m => Accessor.T r a -> (a -> a) -> m a modifyAndGet f g = do modify f g get f infix 1 %=, %: {- | Infix variant of 'set'. -} (%=) :: MonadState r m => Accessor.T r a -> a -> m () (%=) = set {- | Infix variant of 'modify'. -} (%:) :: MonadState r m => Accessor.T r a -> (a -> a) -> m () (%:) = modify -- * lift a state monadic accessor to an accessor of a parent record lift :: (MonadState r mr) => Accessor.T r s -> State s a -> mr 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 :: (Monad m, MonadTrans t, MonadState r (t m)) => Accessor.T r s -> StateT s m a -> t m a liftT f m = do s0 <- get f (a,s1) <- Trans.lift $ runStateT m s0 set f s1 return a {- not possible in this generality lift :: (MonadState r mr, MonadState s ms) => Accessor.T r s -> ms a -> mr a -}