Contact/support | Changelog

Conduit Breaking Monad Transformer Laws

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Data.Conduit
import qualified Data.Conduit.List as CL
import Control.Monad.State
import Control.Monad.Trans.Class

source :: Source IO ()
source = CL.sourceList $ replicate 10 ()

replaceNum :: Conduit () (StateT Int IO) Int
replaceNum = awaitForever $ \() -> do
    i <- lift get
    lift $ (put $ i + 1) >> (get >>= lift . print)
    yield i

replaceNum' :: Conduit () (StateT Int IO) Int
replaceNum' = awaitForever $ \() -> do
    i <- lift get
    lift $ put $ i + 1
    lift $ get >>= lift . print
    yield i

main :: IO ()
main = do
    x <- source $$ transPipe (flip evalStateT 1) replaceNum =$ CL.consume
    print x
    
    x <- source $$ transPipe (flip evalStateT 1) replaceNum' =$ CL.consume
    print x
12:12: Warning: Redundant $
Found:
(put $ i + 1) >> (get >>= lift . print)
Why not:
put (i + 1) >> (get >>= lift . print)
24:30: Warning: Use section
Found:
(flip evalStateT 1)
Why not:
(`evalStateT` 1)
27:30: Warning: Use section
Found:
(flip evalStateT 1)
Why not:
(`evalStateT` 1)