In this recipe, we will use the State Monad as defined by the mtl library. The mtl library defines many useful, well-articulated monads. We will use the State Monad to calculate a fibonacci number.
Computing a fibonacci number with State Monad
How to do it...
- Create a new project using the simple Stack template:
stack new fibonacci-state simple
- Open fibonacci-state.cabal and add packages mtl and containers to the build-depends subsection of the executable section:
executable fibonacci-state
hs-source-dirs: src
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, mtl
, containers
- Build the project...