In this recipe, we will work with IORef, a mutable reference in the IO monad. We will use IORef Int as a counter for the progress that can be tracked from a separate thread, while we do the work in the main thread.
Working with IORef
How to do it...
- Create a new project called working-with-ioref with the simple stack template:
stack new working-with-ioref simple
- Add the ghc-options subsection in the section executable. Add the -threaded option for GHC compilation. If it's not provided, any foreign call will block all Haskell threads. Foreign calls are calls made outside the Haskell runtime (typically by calling functions in external functions):
executable working-with-type-family hs-source...