Import monads doesnt work (leaking haskell platform)
Asked Answered
L

2

13

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?

Lordosis answered 24/11, 2013 at 17:25 Comment(0)
R
19

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
Rachaba answered 24/11, 2013 at 17:32 Comment(5)
now he says: Not in scope: type constructor or class `State', same for Trans.StateLordosis
@Lordosis What did you do? This answer is correct: cabal install mtl.Cristobalcristobalite
yes i did excatly this, and it worked properly, but the error keeps coming ... dont get me wrong, the error changed. i will edit my post to be more precise.Lordosis
UPDATE: i created a new file and extracted the bits with monads, now it seems to work. Thank you all ! now it works ... i just made a very stupid mistake (imported another monad than the one that is used) in the old code.Lordosis
Glad it worked. Now just don't get caught up thinking that MTL is the only monad library. There are others that some like even more (ex: monadlib).Rachaba
J
1

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
Jury answered 15/12, 2018 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.