Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import monads doesnt work (leaking haskell platform)

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?

like image 498
user2664856 Avatar asked Nov 24 '13 17:11

user2664856


2 Answers

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
like image 95
Thomas M. DuBuisson Avatar answered Sep 29 '22 06:09

Thomas M. DuBuisson


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
like image 37
Matthias Braun Avatar answered Sep 29 '22 06:09

Matthias Braun