statestack 0.1.1 → 0.2
raw patch · 3 files changed
+25/−22 lines, 3 filesdep −newtypedep ~basedep ~mtldep ~transformers
Dependencies removed: newtype
Dependency ranges changed: base, mtl, transformers
Files
- CHANGES.md +6/−0
- Control/Monad/StateStack.hs +9/−14
- statestack.cabal +10/−8
+ CHANGES.md view
@@ -0,0 +1,6 @@+0.2: XXX+--------++ * Update to work with latest versions of everything++0.1: Initial release
Control/Monad/StateStack.hs view
@@ -55,7 +55,6 @@ ) where -import Control.Newtype import Data.Monoid import Control.Applicative import Control.Arrow (second)@@ -91,10 +90,6 @@ newtype StateStackT s m a = StateStackT { unStateStackT :: St.StateT (s,[s]) m a } deriving (Functor, Applicative, Monad, MonadTrans, IC.MonadIO) -instance Newtype (StateStackT s m a) (St.StateT (s,[s]) m a) where- pack = StateStackT- unpack = unStateStackT- -- | Class of monads which support a state along with a stack for -- saving and restoring states. class St.MonadState s m => MonadStateStack s m where@@ -102,12 +97,12 @@ restore :: m () -- ^ Restore the top state from the stack instance Monad m => St.MonadState s (StateStackT s m) where- get = pack $ St.gets fst- put s = pack $ (St.modify . first) (const s)+ get = StateStackT $ St.gets fst+ put s = StateStackT $ (St.modify . first) (const s) instance Monad m => MonadStateStack s (StateStackT s m) where- save = pack $ St.modify (fst &&& uncurry (:))- restore = pack . St.modify $ \(cur,hist) ->+ save = StateStackT $ St.modify (fst &&& uncurry (:))+ restore = StateStackT . St.modify $ \(cur,hist) -> case hist of [] -> (cur,hist) (r:hist') -> (r,hist')@@ -116,7 +111,7 @@ -- in a computation of the underlying monad which yields the return -- value and final state. runStateStackT :: Monad m => StateStackT s m a -> s -> m (a, s)-runStateStackT m s = (liftM . second) fst . flip St.runStateT (s,[]) . unpack $ m+runStateStackT m s = (liftM . second) fst . flip St.runStateT (s,[]) . unStateStackT $ m -- | Like 'runStateStackT', but discard the final state. evalStateStackT :: Monad m => StateStackT s m a -> s -> m a@@ -146,7 +141,7 @@ -- | @StateT@ computations can always be lifted to @StateStackT@ -- computations which do not manipulate the state stack. liftState :: Monad m => St.StateT s m a -> StateStackT s m a-liftState st = pack . St.StateT $ \(s,ss) -> (liftM . second) (flip (,) ss) (St.runStateT st s)+liftState st = StateStackT . St.StateT $ \(s,ss) -> (liftM . second) (flip (,) ss) (St.runStateT st s) ------------------------------------------------------------ -- Applying monad transformers to MonadStateStack monads@@ -197,14 +192,14 @@ ------------------------------------------------------------ instance CC.MonadCont m => CC.MonadCont (StateStackT s m) where- callCC c = pack $ CC.callCC (unpack . (\k -> c (pack . k)))+ callCC c = StateStackT $ CC.callCC (unStateStackT . (\k -> c (StateStackT . k))) {- -- These require UndecidableInstances =( instance EC.MonadError e m => EC.MonadError e (StateStackT s m) where throwError = lift . EC.throwError- catchError m h = pack $ EC.catchError (unpack m) (unpack . h)+ catchError m h = StateStackT $ EC.catchError (unStateStackT m) (unStateStackT . h) instance RC.MonadReader r m => RC.MonadReader r (StateStackT s m) where ask = lift RC.ask- local f = pack . RC.local f . unpack+ local f = StateStackT . RC.local f . unStateStackT -}
statestack.cabal view
@@ -1,22 +1,24 @@ Name: statestack-Version: 0.1.1+Version: 0.2 Synopsis: Simple State-like monad transformer with saveable and restorable state Description: Simple State-like monad transformer where states can be saved to and restored from an internal stack. License: BSD3 License-file: LICENSE+Extra-source-files: CHANGES.md Author: Brent Yorgey Maintainer: byorgey@cis.upenn.edu Category: Control Build-type: Simple-Cabal-version: >=1.6+Cabal-version: >=1.10+Bug-reports: http://github.com/diagrams/statestack/issues Source-repository head- type: darcs- location: http://patch-tag.com/r/byorgey/statestack+ type: git+ location: git://github.com/diagrams/statestack Library+ Default-language: Haskell2010 Exposed-modules: Control.Monad.StateStack- Build-depends: base >= 4.2 && < 4.6,- mtl >= 2.0 && < 2.1,- transformers >= 0.2.2.0 && < 0.3,- newtype >= 0.2 && < 0.3+ Build-depends: base >= 4.2 && < 4.8,+ mtl >= 2.1 && < 2.2,+ transformers >= 0.3 && < 0.4