Working with IORef
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.
How to do it...
- Create a new project called
working-with-iorefwith thesimplestack template:
stack new working-with-ioref simple
- Add the
ghc-optionssubsection in the sectionexecutable. Add the-threadedoption 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-dirs: src
main-is: Main.hs
ghc-options: -threaded
default-language: Haskell2010
build-depends: base >= 4.7 && < 5- Open
src/Main.hs. We will be adding our source here. Define theMainmodule:
...