I am trying to solve a problem where Haskell gives different output to the same arguments. someone already has suggested that it could be a thread related issue.
I managed to rewrite a simple function to use the atomic version, but with more complex one I need help.
This is my code:
timeFun globalModel canvas = modifyIORef' globalModel (updateGlobalModel Tick) >> Gtk.widgetQueueDraw canvas >> return True
My findings
Following the advice I tried to rewrite the function using do notation:
timerFun g c = do
i <- readIORef g
writeIORef g (updateGlobalModel Tick i)
Gtk.widgetQueueDraw c
return True
Version that uses atomic code and do notation:
timerFun g c = do
atomicModifyIORef' g $ \p -> do
(updateGlobalModel Tick p ,())
Gtk.widgetQueueDraw c
return True
The key to solving the problem was rewriting the function using do notation.
At this point I had writeIORef separated from other functions, so rewriting it using atomicModifyIORef' was trivial.
Same function with less syntactic sugar