Passing an IO value through several functions results in program hanging.
I came across this rather interesting bug while writing my dissertation.
The following function takes an IO Obs and if it is an observable of time (ObsTime) it increments the contained Int. Otherwise it leaves it unchanged:
incTime :: IO Obs -> IO Obs incTime o = do obs <- o case obs of ObsTime t -> return $ ObsTime (t+1) _ -> o
The case for ObsTime works as expected however, the wildcard case gets progressively slower the more times a value is passed through. At 30 iterations I waited 10 seconds before aborting execution, the function had still not returned.
This issue does not occur with the following change to the wildcard case:
_ -> return obs
This issue occurs both in GHCi and after compiling with GHC (with and without -O2).
It might also be worth mentioning that I've had the issue on Ubuntu (GHC 8.4.2 & 7.10.3) and Windows 7 (GHC 8.0.2). So it doesn't seem to be OS specific or caused by a recent change to GHC.
I have attached a file with the necessary code to demonstrate the issue.