module Main (main) where import Control.Monad (liftM) import Control.Monad.State (State, runState, evalState, get, put) main :: IO () main = do xs <- readFile "data" ys <- readFile "data" print (evalState readChunks xs == ys) --- type FirstMonad = State String readChunks :: FirstMonad String readChunks = do xs <- get if null xs then return [] else do chunk <- case foo xs of (ys, zs) -> do put zs return ys chunks <- readChunks return (chunk ++ chunks) --- type SecondMonad = State String foo :: String -> (String, String) foo = runState bar bar :: SecondMonad String bar = do inp <- get case inp of [] -> return [] x:xs -> do put xs liftM (x:) bar