Quantcast
Channel: Use two monads without a transformer - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Answer by Daniel Wagner for Use two monads without a transformer

The problem you're having is that the hand-unrolling of StateT s IO a is s -> IO (s, a), not IO (s -> (s, a))! Once you have this insight, it's pretty easy to see how to do it:go :: Int -> IO...

View Article



Answer by Matt for Use two monads without a transformer

Maybe this is what you are looking for?main = print =<< fmap (`evalState` 0) (go get) where go :: State Int Int -> IO (State Int Int) go st = do l <- getLine if null l then return (st...

View Article

Answer by dfeuer for Use two monads without a transformer

You'd just need to run the accumulated state computation on every line. This is O(n²) time, but since your first program is already using O(n) space, that's not too terrible. Of course, the StateT...

View Article

Use two monads without a transformer

In order to understand how to use monad transformers, I wrote the following code without one. It reads standard input line by line and displays each line reversed until an empty line is encountered. It...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images