
#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 Burtannia): Replying to [comment:5 danilo2]: I think you were right that it's to do with the strictness of the value. I don't know a huge amount but here is my interpretation.
{{{ !r <- mr -- | Performance buildLayerFold @t @m @layer layer $! pure r }}}
This performs the monadic action `mr`, binds the result to `r` and forces that value to be fully evaluated. `$! pure r` forces `pure r` to be fully evaluated. Note that `pure r` isn't a value, it's a monadic computation that returns a value. From what I understand, your test:
{{{ !_ <- mr buildLayerFold @t @m @layer layer mr }}}
isn't doing what you think it's doing. `!_ <- mr` says ''perform the monadic action `mr` and strictly evaluate its result''. You then pass the monadic action `mr` as an argument to the function on the next line. Note that the computation `mr` is not strictly evaluated here. Later during the execution, that computation will be performed again but must first be evaluated. I'm presuming this "second evaluation" is why it runs two times slower. Again I'm not 100% sure that I'm correct on this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15143#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler