data-accessor-monadLib (empty) → 0.0.0
raw patch · 4 files changed
+133/−0 lines, 4 filesdep +basedep +data-accessordep +monadLibsetup-changed
Dependencies added: base, data-accessor, monadLib
Files
- Data/Accessor/MonadLib.hs +91/−0
- LICENSE +20/−0
- Setup.lhs +4/−0
- data-accessor-monadLib.cabal +18/−0
+ Data/Accessor/MonadLib.hs view
@@ -0,0 +1,91 @@+{- | Access helper functions in State and Reader monads -}+module Data.Accessor.MonadLib + (-- * accessors in the form of actions in the state monad+ set, get, modify+ ,getAndModify, modifyAndGet + ,(%=), (%:)+ -- * lift a state monadic accessor to an accessor of a parent record+ ,lift, liftT+ -- * accessors in the form of actions in the reader monad+ ,ask+ -- * lift a reader monadic accessor to an accessor of a parent record+ ,focusingOn, focusingOnT+ ) where++import qualified MonadLib+import qualified MonadLib.Monads as Monads+import Control.Monad++import qualified Data.Accessor.Basic as Accessor++monadLibModify f = MonadLib.get >>= MonadLib.set . f++set :: MonadLib.StateM m r => Accessor.T r a -> a -> m ()+set f x = monadLibModify (Accessor.set f x)++get :: MonadLib.StateM m r => Accessor.T r a -> m a+get f = (Accessor.get f) `liftM` MonadLib.get++modify :: MonadLib.StateM m r => Accessor.T r a -> (a -> a) -> m ()+modify f g = monadLibModify (Accessor.modify f g)++{- |+Modify a record element and return its old value.+-}+getAndModify :: MonadLib.StateM m r => 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 :: MonadLib.StateM m r => Accessor.T r a -> (a -> a) -> m a+modifyAndGet f g =+ do modify f g+ get f++infix 1 %=, %:++{- |+Infix variant of 'set'.+-}+(%=) :: MonadLib.StateM m r => Accessor.T r a -> a -> m ()+(%=) = set++{- |+Infix variant of 'modify'.+-}+(%:) :: MonadLib.StateM m r => Accessor.T r a -> (a -> a) -> m ()+(%:) = modify++lift :: MonadLib.StateM m r => Accessor.T r s -> Monads.State s a -> m a+lift f m =+ do s0 <- get f+ let (a,s1) = Monads.runState s0 m+ set f s1+ return a++liftT :: (Monad m ) =>+ Accessor.T r s -> MonadLib.StateT s m a -> MonadLib.StateT r m a+liftT f m =+ do s0 <- get f+ (a,s1) <- MonadLib.lift $ MonadLib.runStateT s0 m+ set f s1+ return a++ask :: MonadLib.ReaderM m r => Accessor.T r a -> m a+ask f = (Accessor.get f) `liftM` MonadLib.ask++focusingOn :: MonadLib.ReaderM m r => Accessor.T r s -> Monads.Reader s a -> m a+focusingOn f m =+ do s <- ask f+ return $ Monads.runReader s m+++focusingOnT :: (Monad m ) =>+ Accessor.T r s -> MonadLib.ReaderT s m a -> MonadLib.ReaderT r m a+focusingOnT f m =+ do s <- ask f+ MonadLib.lift $ Monads.runReaderT s m
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2009+Russell O'Connor++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell+ +> import Distribution.Simple+> main = defaultMain
+ data-accessor-monadLib.cabal view
@@ -0,0 +1,18 @@+Name: data-accessor-monadLib+Version: 0.0.0+Cabal-Version: >= 1.2+License: OtherLicense+License-file: LICENSE+Author: Russell O'Connor+Maintainer: Russell O'Connor <roconnor@theorem.ca>+Build-Type: Simple+Category: data, monad+Synopsis: Accessor functions for monadLib's monads+Tested-with: GHC == 6.8.2++Library+ Build-Depends: base < 4.1,+ data-accessor >= 0.1 && < 0.3,+ monadLib >= 3.4 && < 3.6+ Exposed-Modules: Data.Accessor.MonadLib+