diff --git a/common/Utils.hs b/common/Utils.hs index 40f7fbd..5d75ab8 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -21,6 +21,7 @@ with this program. If not, see . module Utils where import Control.Monad +import Control.Monad.State.Class import Data.Ord import System.IO import System.IO.Error @@ -141,3 +142,9 @@ seqPair (x,y) = do x' <- x -- Taken from: http://www.haskell.org/haskellwiki/Blow_your_mind powerset :: [a] -> [[a]] powerset = filterM (const [True, False]) + +-- | Alters a monadic state and returns the old value (from before the alteration). +modify' :: MonadState s m => (s -> s) -> m s +modify' f = do x <- get + put (f x) + return x