Question

As there is no haskell-plattform for the newest Ubuntu 13.04, I only downloaded the GHCi and had no problems until now.

But now I want to work with monads. Importing them with

import Control.Monad.State

for example does not work. The error message:

Could not find module `Control.Monad.State'
Perhaps you meant
  Control.Monad.ST (from base)
  Control.Monad.ST.Safe (from base)
  Control.Monad.Fix (from base)
Use -v to see a list of the files searched for.
Failed, modules loaded: none.

How can I manually download them, or is there an entirely different problem?

Was it helpful?

Solution

You need to install the library somewhere GHC can find it.

Installing via Cabal

Install Cabal

If you haven't installed cabal-install then do that first. Do this one of two ways.

Via OS Packaging:

sudo apt-get install cabal-install

or manually:

wget http://hackage.haskell.org/package/cabal-install-1.18.0.2/cabal-install-1.18.0.2.tar.gz
tar xzf cabal-install-1.18.0.2.tar.gz
cd cabal-install-1.18.0.2
sh ./bootstrap.sh
export PATH=$PATH:$HOME/.cabal/bin

Use Cabal

Once you have installed cabal-install then do:

cabal update
cabal install mtl

This is the "Monad Transformer Library" which includes many common monads, such as State, that you see used in examples.

Install via OS Packaging

Alternative to all of this is to install the ubuntu packaging of mtl. That said, I don't know any active Haskell developers who use OS packagings of Haskell packages instead of cabal. The ubuntu package is libghc-ghc-mtl-dev:

sudo apt-get install libghc-ghc-mtl-dev

OTHER TIPS

Using Stack

If you're using Stack, you can get the monad transformer library by adding transformers to the dependencies of your package.yml:

executables:
  state-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - state
    - transformers
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top