How do i use Debug.Trace.trace in the state monad?

Viewed 2131

I want to keep track of changes in the state monad. This does not work:

main :: IO ()
main = do
    print $ snd $ execState compute initialState

traceThis :: (Show a) => a -> a
traceThis x = trace ("test: " ++ show x) x

compute :: State ([Row], Integer) String
compute = liftM traceThis $ get >>= \(rs, result) -> put (rs, result + 3) >> return "foo"

Nothing gets printed (except the end result from the print in the main function which has correctly been updated).

Any ideas or alternatives to track state? I want to use this for checking correctness of a project euler solution.

3 Answers
Related