Search code examples
haskellcabal

Module can not be imported after installing via cabal


I tried using the primes module in Haskell and after running

$ cabal install primes 

Resolving dependencies...
Notice: installing into a sandbox located at /home/christoph/.cabal-sandbox
Downloading primes-0.2.1.0...
Configuring primes-0.2.1.0...
Building primes-0.2.1.0...
Installed primes-0.2.1.0

I tried making a file with

import Data.Numbers.Primes

at the top, but every attempt to load it failed with the error message:

Could not find module ‘Data.Numbers.Primes’
Use -v to see a list of the files searched for.

The question: what am I missing here? there must be something wrong with this way of using it right?

After reading Haskell: where is Data.Numbers.Primes library? I also tried:

import Data.Primes
import primes
import Primes

but none of them worked.

Thank you in advance, any help is most welcome


Solution

  • Because you are installing the primes package to a sandbox, you will need to run the compiler with awareness of the sandbox. cabal offers the exec command for this, so e.g.

    echo import Data.Numbers.Primes >foo.hs
    cabal exec ghci foo.hs
    

    from within the sandbox should work.