packages feed

data-accessor-monads-tf (empty) → 0.2.1

raw patch · 4 files changed

+126/−0 lines, 4 filesdep +basedep +data-accessordep +monads-tfsetup-changed

Dependencies added: base, data-accessor, monads-tf, transformers

Files

+ LICENSE view
@@ -0,0 +1,26 @@+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 the <organization>; 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.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#! /usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ data-accessor-monads-tf.cabal view
@@ -0,0 +1,17 @@+Name:             data-accessor-monads-tf+Version:          0.2.1+License:          BSD3+License-File:     LICENSE+Author:           Stephan Friedrichs+Maintainer:       Stephan Friedrichs (deduktionstheorem at web dot de)+Homepage:         http://www.haskell.org/haskellwiki/Record_access+Package-URL:      http://code.haskell.org/data-accessor/+Category:         Data+Build-Type:       Simple+Build-Depends:    base>=1.0, data-accessor >=0.2 && <0.3, monads-tf >=0.0 && <0.1, transformers >=0.0.1 && <0.2+Synopsis:         Use Accessor to access state in monads-tf State monad type family+Description:      Use Accessor to access state in monads-tf State monad type family+GHC-Options:      -Wall+Hs-Source-Dirs:   src+Exposed-Modules:+  Data.Accessor.Monad.TF.State
+ src/Data/Accessor/Monad/TF/State.hs view
@@ -0,0 +1,80 @@+{- | Access helper functions in the State monad type family -}+module Data.Accessor.Monad.TF.State where++import qualified Control.Monad.State as State+import Control.Monad.State (MonadState, StateType)+import Control.Monad.Trans (MonadTrans)+import qualified Control.Monad.Trans as Trans+import Control.Monad.Trans.State (State, runState, StateT, runStateT)+import qualified Data.Accessor.Basic as Accessor++-- * accessors in the form of actions in the state monad++set :: MonadState m => Accessor.T (StateType m) a -> a -> m ()+set f x = State.modify (Accessor.set f x)++get :: MonadState m => Accessor.T (StateType m) a -> m a+get f = State.gets (Accessor.get f)++modify :: MonadState m => Accessor.T (StateType m) a -> (a -> a) -> m ()+modify f g = State.modify (Accessor.modify f g)++{- |+Modify a record element and return its old value.+-}+getAndModify :: MonadState m => Accessor.T (StateType m) 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 m => Accessor.T (StateType m) a -> (a -> a) -> m a+modifyAndGet f g =+   do modify f g+      get f++++infix 1 %=, %:++{- |+Infix variant of 'set'.+-}+(%=) :: MonadState m => Accessor.T (StateType m) a -> a -> m ()+(%=) = set++{- |+Infix variant of 'modify'.+-}+(%:) :: MonadState m => Accessor.T (StateType m) a -> (a -> a) -> m ()+(%:) = modify++++-- * lift a state monadic accessor to an accessor of a parent record++lift :: (MonadState mr) =>+   Accessor.T (StateType mr) 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 (t m)) =>+   Accessor.T (StateType (t m)) 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+-}