
#15143: Passing an IO value through several functions results in program hanging. -------------------------------------+------------------------------------- Reporter: Burtannia | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): It is nothing to do with strictness! Consider {{{ foo :: IO Int -> IO Int foo a = do { i1 <- a ; i2 <- a ; return (i1+i2) } }}} This function must perform `a` twice. It is ''not'' ok to "optimise" it to {{{ foo a = do { i1 <- a ; return (i1+i1) } }}} Reason: `a` might have side effects (which must be performed twice) and it might return different values on its successive calls. In the example of this ticket, in `incTime` the action `o` must be called twice. And in the particular example, the action is another call to `incTime` which calls its `o` twice; and so on. Result: 2^n calls of the final action, hence exponential behaviour. Strictness and bangs have no effect on this story -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15143#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler