Repository navigation
Conversation
081bda7 to
94ca230
Compare
94ca230 to
83eb097
Compare
| data BaseMonad | ||
| = forall m. (Typeable m, Monad m) => LazyBaseMonad (forall a. m a -> IO a) | ||
| | forall m. (Typeable m, Monad m) => StrictBaseMonad (forall a. m a -> IO a) | ||
| = forall m. (Typeable m, Monad m) => BaseMonad (forall a. m a -> IO a) |
There was a problem hiding this comment.
I simplified this to just BaseMonad since there are different nuances of strictness which can get complicated to categorize.
Instead, if there is a difference in the behavior depending on the underlying monad, I opted to just check the actual monad type directly and explain with a comment, as done in one of the tests here.
Please let me know if you have any thoughts.
There was a problem hiding this comment.
Just the strictness assertions moved out of the writer tests
| -- In general, the computations are lazy since this is the Lazy State. | ||
| -- | ||
| -- However, one exception is modify', which enforces strictness on the state value. | ||
| -- Thus, modify' will bottom for monads which are strict in the underlying sequencing. | ||
| -- i.e. Solo and IO | ||
| -- | ||
| -- In particular, note that Identity is lazy whereas Solo is strict: | ||
| -- | ||
| -- m >>= k = k (runIdentity m) lazy runIdentity | ||
| -- MkSolo x >>= k = k x strict pattern match | ||
| -- | ||
| let expected = (baseMonadName m == "Solo" || baseMonadName m == "IO") && isBottom (f (snd (x 0))) | ||
| in shouldBeBottomIO expected $ withBaseMonad m $ flip Lazy.runStateT 0 $ do | ||
| p <- Lazy.StateT $ return . x | ||
| q <- Lazy.get | ||
|
|
||
| Lazy.modify' f -- may throw depending on the underlying monad. See above. |
There was a problem hiding this comment.
The example mentioned above.
83eb097 to
1781938
Compare
L0neGamer
left a comment
There was a problem hiding this comment.
Pretty darn good! Very happy with what you've done here.
| main = do | ||
| ComposeT.test | ||
| WriterStrictness.test | ||
| defaultMain $ testGroup "Transformers" [ |
There was a problem hiding this comment.
possibly "transformers strictness"
| testGroup "evalStateT" [ | ||
| testProperty "Lazy" $ \(F1Bot (x :: () -> (Int, ()))) -> | ||
| let result = flip Lazy.evalStateT () $ Lazy.StateT (MkSolo . x) | ||
| in isLazy result .&. isStrictIn (x ()) (getSolo result), | ||
| testProperty "Strict" $ \(F1Bot (x :: () -> (Int, ()))) -> | ||
| let result = flip Strict.evalStateT () $ Strict.StateT (MkSolo . x) | ||
| in isLazy result .&. isStrictIn (x ()) (getSolo result) | ||
| ], | ||
| testGroup "execStateT" [ | ||
| -- NOTE: See note on evalStateT. | ||
| testProperty "Lazy" $ \(F1Bot (x :: () -> (Int, ()))) -> | ||
| let result = flip Lazy.execStateT () $ Lazy.StateT (MkSolo . x) | ||
| in isLazy result .&. isStrictIn (x ()) (getSolo result), | ||
| testProperty "Strict" $ \(F1Bot (x :: () -> (Int, ()))) -> | ||
| let result = flip Strict.execStateT () $ Strict.StateT (MkSolo . x) | ||
| in isLazy result .&. isStrictIn (x ()) (getSolo result) | ||
| ], |
There was a problem hiding this comment.
with all of these tests, does the underlying monad type not change anything?
|
I'll try give another review over the week. I couldn't see much wrong so it'll likely be an approval! |
Tests for the Lazy|Strict State transformer.
The approach is analogous to the Writer tests in #127.
evalStateT,execStateT,mapStateT,withStateT,put,modify,modify',modifyMgetsfmap,<*>,liftA2,>>=(same as the Writer tests)liftListen,liftPass, since the behavior differs for these, as it did also in the Writer transformers