stateWriter 0.2.8.2 → 0.2.9
raw patch · 4 files changed
+21/−13 lines, 4 files
Files
- Control/Monad/Trans/RSS/Lazy.hs +3/−3
- Control/Monad/Trans/RSS/Strict.hs +5/−4
- stateWriter.cabal +1/−1
- tests/rwscompare.hs +12/−5
Control/Monad/Trans/RSS/Lazy.hs view
@@ -164,9 +164,9 @@ tell w = RSST $ \_ (s, ow) -> let nw = ow <> w in return ((), (s, nw))- listen rw = RSST $ \r s -> do- (a, (ns, nw)) <- runRSST' rw r s- return ((a, nw), (ns, nw))+ listen rw = RSST $ \r (s, w) -> do+ (a, (ns, nw)) <- runRSST' rw r (s, mempty)+ return ((a, nw), (ns, w <> nw)) pass rw = RSST $ \r (s, w) -> do ( (a, fw), (s', w') ) <- runRSST' rw r (s, mempty) return (a, (s', w `mappend` fw w'))
Control/Monad/Trans/RSS/Strict.hs view
@@ -161,10 +161,11 @@ writer (a,w) = tell w >> return a tell w = RSST $ \_ (s, ow) -> let nw = ow `mappend` w- in nw `seq` return ((), (s, ow `mappend` w))- listen rw = RSST $ \r s -> do- (a, (ns, nw)) <- runRSST' rw r s- return ((a, nw), (ns, nw))+ in nw `seq` return ((), (s, nw))+ listen rw = RSST $ \r (s, w) -> do+ (a, (ns, nw)) <- runRSST' rw r (s,mempty)+ let ow = w `mappend` nw+ ow `seq` return ((a, nw), (ns, ow)) pass rw = RSST $ \r (s, w) -> do ( (a, fw), (s', w') ) <- runRSST' rw r (s, mempty) return (a, (s', w `mappend` fw w'))
stateWriter.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: stateWriter-version: 0.2.8.2+version: 0.2.9 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
tests/rwscompare.hs view
@@ -7,6 +7,7 @@ import Test.QuickCheck import Control.Applicative import Control.Monad.Free+import Prelude data ActionF next = Tell [Int] next | SetState Int next@@ -67,9 +68,15 @@ main :: IO () main = hspec $ do- describe "Writer part" $ do- it "logs stuff in the right order, with tell" $- property $ \listOfLists -> runRSS (mapM_ tell (listOfLists :: [[Int]])) () () == runRWS (mapM_ tell listOfLists) () ()- it "interprets actions the same" $- property $ \actions -> runRSS (evaluateActions (actions :: Action Int)) 42 12 == runRWS (evaluateActions actions) 42 12+ describe "Writer part" $ do+ it "logs stuff in the right order, with tell" $+ property $ \listOfLists -> runRSS (mapM_ tell (listOfLists :: [[Int]])) () () == runRWS (mapM_ tell listOfLists) () ()+ it "listen" $+ runRSS (tell "lol" >> listen (return ())) () () `shouldBe` (((),""),(),"lol")+ it "listen" $+ runRSS (tell "lol" >> listen (tell "lal")) () () `shouldBe` (((),"lal"),(),"lollal")++ describe "RWS comparison" $+ it "interprets actions the same" $+ property $ \actions -> runRSS (evaluateActions (actions :: Action Int)) 42 12 == runRWS (evaluateActions actions) 42 12