stateWriter 0.2.10 → 0.4.0
raw patch · 5 files changed
Files
- Control/Monad/Trans/RSS/Lazy.hs +2/−0
- Control/Monad/Trans/RSS/Strict.hs +2/−0
- stateWriter.cabal +3/−3
- tests/rwscompare.hs +9/−0
- tests/spaceleak.hs +11/−11
Control/Monad/Trans/RSS/Lazy.hs view
@@ -128,6 +128,8 @@ m >>= k = RSST $ \r s -> do ~(a, (s', w)) <- runRSST' m r s runRSST' (k a) r (s',w)++instance (MonadFail m) => MonadFail (RSST r w s m) where fail msg = RSST $ \_ _ -> fail msg instance (MonadPlus m) => MonadPlus (RSST r w s m) where
Control/Monad/Trans/RSS/Strict.hs view
@@ -131,6 +131,8 @@ (a, (s', w)) <- runRSST' m r s runRSST' (k a) r (s',w) {-# INLINE (>>=) #-}++instance (MonadFail m) => MonadFail (RSST r w s m) where fail msg = RSST $ \_ _ -> fail msg instance (MonadPlus m) => MonadPlus (RSST r w s m) where
stateWriter.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: stateWriter-version: 0.2.10+version: 0.4.0 synopsis: A faster variant of the RWS monad transformers. description: This is a version of the RWS monad transformers that should be much faster than what's found in transformers. The writer in the strict version does not leak memory. license: BSD3@@ -14,7 +14,7 @@ build-type: Simple -- extra-source-files: cabal-version: >=1.10-Tested-With: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1, GHC == 8.2.1+Tested-With: GHC == 8.8.4, GHC == 8.10.2, GHC == 9.4.5 source-repository head type: git@@ -24,7 +24,7 @@ exposed-modules: Control.Monad.Trans.RSS.Lazy, Control.Monad.Trans.RSS.Strict, Control.Monad.RSS.Lazy, Control.Monad.RSS.Strict, Control.Monad.RSS, Control.Monad.Trans.RSS ghc-options: -Wall other-extensions: FlexibleInstances, MultiParamTypeClasses- build-depends: base >=4.6 && < 5, transformers >=0.3 && <0.6, mtl >=2.1 && <2.3+ build-depends: base >= 4.13 && < 5, transformers >=0.3 && <0.7, mtl >=2.1 && <2.4 default-language: Haskell2010 test-suite spaceleak
tests/rwscompare.hs view
@@ -5,6 +5,7 @@ import Control.Monad.RWS import Test.Hspec import Test.QuickCheck+import Data.Functor.Classes import Control.Applicative import Control.Monad.Free import Prelude@@ -57,6 +58,14 @@ show (AskAndStore i n) = "AskAndStore " ++ show i ++ " / " ++ show n show (GetAndStore i n) = "GetAndStore " ++ show i ++ " / " ++ show n show (Modify s n) = "Modify " ++ show s ++ " / " ++ show n++instance Show1 ActionF where+ liftShowsPrec showp _ _ a = case a of+ Tell x n -> showString "Tell " . shows x . showString " / " . showp 0 n+ SetState s n -> showString "Set " . shows s . showString " / " . showp 0 n+ AskAndStore i n -> showString "AskAndStore " . shows i . showString " / " . showp 0 n+ GetAndStore i n -> showString "GetAndStore " . shows i . showString " / " . showp 0 n+ Modify s n -> showString "Modify " . shows s . showString " / " . showp 0 n evaluateActions :: (MonadRWS Int [Int] Int m) => Action x -> m x evaluateActions (Free (Tell x next)) = tell x >> evaluateActions next
tests/spaceleak.hs view
@@ -1,22 +1,22 @@- module Main where +import Control.Monad import qualified Control.Monad.Trans.RSS.Lazy as RSSL import qualified Control.Monad.Trans.RSS.Strict as RSSS-import System.Environment import Control.Monad.Writer+import Data.Monoid (Sum (..))+import System.Environment n :: Int n = 10000000 main :: IO () main = do- print $ RSSS.runRSS (replicateM_ n $ tell $ Sum (1 :: Int)) () ()- tryExplode <- fmap (not . null) getArgs- if tryExplode- then do- putStrLn "Strict version ok, the next test should explode the stack."- print $ RSSL.runRSS (replicateM_ n $ tell $ Sum (1 :: Int)) () ()- putStrLn "Lazy version should have exploded !"- else- putStrLn "Do not try exploding the stack. Run the test program with any command line argument to test it"+ print $ RSSS.runRSS (replicateM_ n $ tell $ Sum (1 :: Int)) () ()+ tryExplode <- fmap (not . null) getArgs+ if tryExplode+ then do+ putStrLn "Strict version ok, the next test should explode the stack."+ print $ RSSL.runRSS (replicateM_ n $ tell $ Sum (1 :: Int)) () ()+ putStrLn "Lazy version should have exploded !"+ else putStrLn "Do not try exploding the stack. Run the test program with any command line argument to test it"