1

I'm trying to load my .hs file but when I import Data.Numbers.CReal, it gives me the error Failed to load interface for 'Data.Numbers.CReal'. I have runned cabal install numbers and if I cabal list --installed the number pkg appears, but if I ghc-pkg list it doesn't (also if I ghc-pkg checkit gives LOTS of haddock warnings). Is it related to my non-loading file? How can I solve this?

Ps. I know how to import packages, but I'm not sure if I am importing this one properly.

Thanks and sorry if I didn't explained myself correctly.

0

2 Answers 2

3

Two hypotheses spring to mind:

  1. cabal is choosing a different version of ghc and its attending toolsuite than your shell is. You can check for this discrepancy by running these two commands:

    cabal exec -- ghc --version
    ghc --version
    

    Do they say the same thing? If so, reject this hypothesis. Otherwise you should decide whether you like the shell's choice or cabal's choice better (I recommend preferring your shell's choice).

    If you like cabal's choice better, you can use a specific version of GHC (and other GHC tools) by appending -<version> to the command; e.g. try ghc-pkg-7.10.3 list to see what is in the package database for version 7.10.3, or ghci-7.10.3 to run a specific version of the REPL. You can make these changes permanent by adding symlinks or similar to your PATH.

    If you like your shell's choice better, you can ask cabal to use that version with cabal configure -w ghc; or if you are worried that cabal and your shell will resolve ghc differently, you could ask for a specific version with cabal configure -w ghc-7.10.3 or similar.

  2. Your shell agrees with cabal about what version of GHC to use, but you are in a cabal sandbox. cabal list --installed is telling you what's installed in the sandbox, but ghc-pkg list is telling you what's installed in your user package database. You can check for discrepancies between these two commands:

    cabal exec -- ghc-pkg list numbers
    ghc-pkg list numbers
    

    (If you have a newish cabal -- not sure which version this appeared in -- you could also try cabal hc-pkg list instead of cabal exec -- ghc-pkg list. This is likely to be the more forward-compatible way, so a good habit to develop.)

    If these print the same things, reject this hypothesis. Otherwise you should decide whether you want to continue using a sandbox or not (I recommend continuing to use a sandbox).

    If you want to stop using a sandbox, you can pass --ignore-sandbox to cabal. To make this permanent, look in the cabal.sandbox.config file, which will contain a pointer to the actual sandbox (usually .cabal.sandbox). Delete both the config and the sandbox. You can also globally ignore sandboxes by adding ignore-sandbox: True to your ~/.cabal/config, but I strongly recommend against this.

    If you want to keep the sandbox, you will need to use cabal exec for all of your GHC toolsuite needs to make sure the correct package database is selected. For example, try cabal exec ghci to run the REPL with access to the sandbox package database.

These hypotheses are not mutually exclusive: both may happen. In that case I strongly recommend choosing the final solution ("use cabal exec for all GHC toolsuite executions"), as it handles both problems transparently: the standard GHC toolsuite commands will be rewritten to refer to explicitly versioned ones (e.g. cabal exec ghc will actually execute ghc-7.10.3) and the environment will be set up to point at the correct package database.

0

The answer to this

You can check for this discrepancy by running these two commands:

cabal exec -- ghc --version ghc --version

Do they say the same thing?

was yes. I don't remember the second option, but I've managed to solve it myself. What I specifically did was:

  1. run the command "rm -rf .cabal" (without commmas) to delete the cabal configuration.
  2. run "rm -rf .cabal-sandbox"
  3. run "rm -rf .ghc"
  4. cabal new-build cabal (not sure if this helped or not)
  5. In admin mode (sudo) I edited the cabal config file and changed Ignore Sandbox to True --> would this give me problems in the future? should I change it back to false? please answer
  6. Had to delete a cabal.sandbox.config that was giving some troubles
  7. cabal install cabal-install
  8. cabal update

Now the ghc-pkg list command and the cabal list --installed show both my installed packages, and they work without problems.

Ps. I gave detailed information from the process in case anyone needs it in the future. Still not sure what caused that cabal and ghc didn't show the same pkgs.

3
  • Note: Do not accidentally delete .cabal/config.
    – sapanoia
    Oct 20, 2017 at 20:37
  • I consider this answer to be the "nuclear option". I strongly recommend that future readers attempt gentler solutions first; e.g. if cabal has chosen a different version of GHC than you wanted, you can use cabal configure to select another version (as in cabal configure -w ghc-7.10.3). I'll edit my answer to include some comments on this solution. Manually deleting cabal sandboxes is okay (currently cabal does not have a way to delete them in a non-manual way), but you should understand why the sandbox exists first and be sure you actually don't want it... Oct 20, 2017 at 21:28
  • Oh, and I misread; given the details here, I strongly suspect my other proposed hypothesis ("you are in a cabal sandbox, and cabal list --installed is telling you what's installed in the sandbox, but ghc-pkg list is telling you what's installed in your user package database") was the correct one. cabal configure won't help with that, but I outline two gentler solutions to this problem in my answer. Oct 20, 2017 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.